From 032ef44dbd19889865dfb86252868ce34cd20def Mon Sep 17 00:00:00 2001 From: disclearing Date: Wed, 13 Feb 2019 12:32:32 +0000 Subject: [PATCH] A bruce boy skid :heart_eyes: --- .DS_Store | Bin 0 -> 6148 bytes .classpath | 31 + .idea/artifacts/Vengeful_jar.xml | 16 + .idea/encodings.xml | 7 + .idea/libraries/PermissionsEx_1_23_4.xml | 18 + .idea/libraries/spigot.xml | 11 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 595 ++ .project | 17 + README.md | 2 + Vengeful.iml | 85 + balances.yml | 1 + bin/.DS_Store | Bin 0 -> 6148 bytes bin/.classpath | 31 + bin/.gitignore | 3 + bin/.idea/artifacts/Vengeful_jar.xml | 16 + bin/.idea/encodings.xml | 7 + bin/.idea/libraries/PermissionsEx_1_23_4.xml | 18 + bin/.idea/libraries/spigot.xml | 11 + bin/.idea/misc.xml | 6 + bin/.idea/modules.xml | 8 + bin/.idea/vcs.xml | 6 + bin/.idea/workspace.xml | 595 ++ bin/.project | 17 + bin/LICENSE | 674 ++ bin/LorexMC/us/utils/BukkitUtils.class | Bin 0 -> 11413 bytes bin/LorexMC/us/utils/Color.class | Bin 0 -> 1263 bytes ...currentValueOrderedMap$InternalEntry.class | Bin 0 -> 2250 bytes .../us/utils/ConcurrentValueOrderedMap.class | Bin 0 -> 3357 bytes bin/LorexMC/us/utils/Config.class | Bin 0 -> 2794 bytes .../us/utils/DelayedMessageRunnable.class | Bin 0 -> 885 bytes bin/LorexMC/us/utils/DurationFormatter.class | Bin 0 -> 1726 bytes bin/LorexMC/us/utils/ExperienceManager.class | Bin 0 -> 4685 bytes bin/LorexMC/us/utils/GenericUtils.class | Bin 0 -> 4034 bytes .../us/utils/InventorySerialisation.class | Bin 0 -> 3859 bytes bin/LorexMC/us/utils/InventoryUtils.class | Bin 0 -> 5113 bytes bin/LorexMC/us/utils/ItemBuilder.class | Bin 0 -> 3650 bytes bin/LorexMC/us/utils/JavaUtils.class | Bin 0 -> 6251 bytes bin/LorexMC/us/utils/MapSorting$1.class | Bin 0 -> 1137 bytes bin/LorexMC/us/utils/MapSorting$2.class | Bin 0 -> 1139 bytes bin/LorexMC/us/utils/MapSorting.class | Bin 0 -> 2928 bytes bin/LorexMC/us/utils/NmsUtils.class | Bin 0 -> 3222 bytes bin/LorexMC/us/utils/ParticleEffect.class | Bin 0 -> 9830 bytes .../us/utils/PersistableLocation.class | Bin 0 -> 7060 bytes bin/LorexMC/us/utils/SignHandler$1.class | Bin 0 -> 1887 bytes .../us/utils/SignHandler$SignChange.class | Bin 0 -> 643 bytes bin/LorexMC/us/utils/SignHandler.class | Bin 0 -> 5992 bytes bin/LorexMC/us/utils/SpigotUtils.class | Bin 0 -> 2713 bytes bin/LorexMC/us/utils/UUIDFetcher.class | Bin 0 -> 5951 bytes .../collect/FluentIterableCompat$1.class | Bin 0 -> 1108 bytes .../common/collect/FluentIterableCompat.class | Bin 0 -> 3345 bytes .../google/common/collect/GuavaCompat.class | Bin 0 -> 1677 bytes .../com/bruce/base/BaseConstants.class | Bin 0 -> 887 bytes .../internal/com/bruce/base/BasePlugin.class | Bin 0 -> 2345 bytes .../internal/com/bruce/base/Callback.class | Bin 0 -> 299 bytes .../us/utils/other/chat/ChatUtil.class | Bin 0 -> 6241 bytes .../us/utils/other/chat/ClickAction.class | Bin 0 -> 1612 bytes .../us/utils/other/chat/HoverAction.class | Bin 0 -> 1538 bytes bin/LorexMC/us/utils/other/chat/Lang.class | Bin 0 -> 5591 bytes bin/LorexMC/us/utils/other/chat/Text.class | Bin 0 -> 6517 bytes bin/LorexMC/us/utils/other/chat/Trans.class | Bin 0 -> 5744 bytes .../other/command/ArgumentExecutor.class | Bin 0 -> 5352 bytes .../utils/other/command/CommandArgument.class | Bin 0 -> 3363 bytes .../CommandWrapper$ArgumentComparator.class | Bin 0 -> 1224 bytes .../utils/other/command/CommandWrapper.class | Bin 0 -> 5357 bytes .../utils/other/cuboid/CoordinatePair.class | Bin 0 -> 1733 bytes .../us/utils/other/cuboid/Cuboid.class | Bin 0 -> 16941 bytes .../other/cuboid/CuboidBlockIterator.class | Bin 0 -> 1786 bytes .../utils/other/cuboid/CuboidDirection.class | Bin 0 -> 2682 bytes .../other/cuboid/CuboidLocationIterator.class | Bin 0 -> 1759 bytes .../us/utils/other/cuboid/NamedCuboid.class | Bin 0 -> 2914 bytes .../utils/other/imagemessage/ImageChar.class | Bin 0 -> 1402 bytes .../other/imagemessage/ImageMessage.class | Bin 0 -> 7829 bytes .../us/utils/other/itemdb/ItemData.class | Bin 0 -> 4512 bytes .../us/utils/other/itemdb/ItemDb.class | Bin 0 -> 732 bytes .../us/utils/other/itemdb/ManagedFile.class | Bin 0 -> 5197 bytes .../utils/other/itemdb/SimpleItemDb$1.class | Bin 0 -> 870 bytes .../us/utils/other/itemdb/SimpleItemDb.class | Bin 0 -> 11496 bytes bin/README.md | 2 + bin/Vengeful.iml | 85 + bin/balances.yml | 1 + bin/config.yml | 87 + bin/coords.txt | 0 bin/enderdragon-art-old.png | Bin 0 -> 3117 bytes bin/enderdragon-art.png | Bin 0 -> 3142 bytes bin/event-schedules.txt | 2 + bin/faction-users.yml | 1 + bin/factions.yml | 1 + bin/gopple-art.png | Bin 0 -> 19318 bytes bin/help.txt | 0 bin/items.csv | 7451 +++++++++++++++++ bin/lives.yml | 1 + bin/locale.yml | 107 + bin/plugin.yml | 130 + bin/settings.yml | 75 + bin/timers.yml | 0 config.yml | 87 + coords.txt | 0 enderdragon-art-old.png | Bin 0 -> 3117 bytes enderdragon-art.png | Bin 0 -> 3142 bytes event-schedules.txt | 2 + faction-users.yml | 1 + factions.yml | 1 + gopple-art.png | Bin 0 -> 19318 bytes help.txt | 0 items.csv | 7451 +++++++++++++++++ lives.yml | 1 + locale.yml | 107 + plugin.yml | 130 + settings.yml | 75 + src/LorexMC/us/utils/BukkitUtils.java | 181 + src/LorexMC/us/utils/Color.java | 18 + .../us/utils/ConcurrentValueOrderedMap.java | 89 + src/LorexMC/us/utils/Config.java | 93 + .../us/utils/DelayedMessageRunnable.java | 22 + src/LorexMC/us/utils/DurationFormatter.java | 30 + src/LorexMC/us/utils/ExperienceManager.java | 134 + src/LorexMC/us/utils/GenericUtils.java | 69 + .../us/utils/InventorySerialisation.java | 75 + src/LorexMC/us/utils/InventoryUtils.java | 117 + src/LorexMC/us/utils/ItemBuilder.java | 84 + src/LorexMC/us/utils/JavaUtils.java | 133 + src/LorexMC/us/utils/MapSorting.java | 84 + src/LorexMC/us/utils/NmsUtils.java | 53 + src/LorexMC/us/utils/ParticleEffect.java | 156 + src/LorexMC/us/utils/PersistableLocation.java | 249 + src/LorexMC/us/utils/SignHandler.java | 124 + src/LorexMC/us/utils/SpigotUtils.java | 79 + src/LorexMC/us/utils/UUIDFetcher.java | 97 + .../common/collect/FluentIterableCompat.java | 48 + .../google/common/collect/GuavaCompat.java | 20 + .../com/bruce/base/BaseConstants.java | 12 + .../internal/com/bruce/base/BasePlugin.java | 76 + .../internal/com/bruce/base/Callback.java | 5 + src/LorexMC/us/utils/other/chat/ChatUtil.java | 69 + .../us/utils/other/chat/ClickAction.java | 18 + .../us/utils/other/chat/HoverAction.java | 18 + src/LorexMC/us/utils/other/chat/Lang.java | 99 + src/LorexMC/us/utils/other/chat/Text.java | 133 + src/LorexMC/us/utils/other/chat/Trans.java | 109 + .../utils/other/command/ArgumentExecutor.java | 107 + .../utils/other/command/CommandArgument.java | 114 + .../utils/other/command/CommandWrapper.java | 97 + .../us/utils/other/cuboid/CoordinatePair.java | 69 + src/LorexMC/us/utils/other/cuboid/Cuboid.java | 519 ++ .../other/cuboid/CuboidBlockIterator.java | 56 + .../utils/other/cuboid/CuboidDirection.java | 68 + .../other/cuboid/CuboidLocationIterator.java | 56 + .../us/utils/other/cuboid/NamedCuboid.java | 57 + .../utils/other/imagemessage/ImageChar.java | 15 + .../other/imagemessage/ImageMessage.java | 182 + .../us/utils/other/itemdb/ItemData.java | 106 + src/LorexMC/us/utils/other/itemdb/ItemDb.java | 26 + .../us/utils/other/itemdb/ManagedFile.java | 76 + .../us/utils/other/itemdb/SimpleItemDb.java | 317 + src/gnu/trove/TByteCollection.java | 313 + src/gnu/trove/TCharCollection.java | 313 + src/gnu/trove/TCollections.java | 4620 ++++++++++ src/gnu/trove/TDecorators.java | 965 +++ src/gnu/trove/TDoubleCollection.java | 314 + src/gnu/trove/TFloatCollection.java | 313 + src/gnu/trove/TIntCollection.java | 313 + src/gnu/trove/TLongCollection.java | 313 + src/gnu/trove/TShortCollection.java | 313 + src/gnu/trove/Version.java | 57 + .../decorator/TByteByteMapDecorator.java | 422 + .../decorator/TByteCharMapDecorator.java | 422 + .../decorator/TByteDoubleMapDecorator.java | 422 + .../decorator/TByteFloatMapDecorator.java | 422 + .../trove/decorator/TByteIntMapDecorator.java | 422 + .../trove/decorator/TByteListDecorator.java | 137 + .../decorator/TByteLongMapDecorator.java | 422 + .../decorator/TByteObjectMapDecorator.java | 374 + .../trove/decorator/TByteSetDecorator.java | 230 + .../decorator/TByteShortMapDecorator.java | 422 + .../decorator/TCharByteMapDecorator.java | 422 + .../decorator/TCharCharMapDecorator.java | 422 + .../decorator/TCharDoubleMapDecorator.java | 422 + .../decorator/TCharFloatMapDecorator.java | 422 + .../trove/decorator/TCharIntMapDecorator.java | 422 + .../trove/decorator/TCharListDecorator.java | 137 + .../decorator/TCharLongMapDecorator.java | 422 + .../decorator/TCharObjectMapDecorator.java | 374 + .../trove/decorator/TCharSetDecorator.java | 230 + .../decorator/TCharShortMapDecorator.java | 422 + .../decorator/TDoubleByteMapDecorator.java | 422 + .../decorator/TDoubleCharMapDecorator.java | 422 + .../decorator/TDoubleDoubleMapDecorator.java | 424 + .../decorator/TDoubleFloatMapDecorator.java | 423 + .../decorator/TDoubleIntMapDecorator.java | 422 + .../trove/decorator/TDoubleListDecorator.java | 137 + .../decorator/TDoubleLongMapDecorator.java | 422 + .../decorator/TDoubleObjectMapDecorator.java | 376 + .../trove/decorator/TDoubleSetDecorator.java | 230 + .../decorator/TDoubleShortMapDecorator.java | 423 + .../decorator/TFloatByteMapDecorator.java | 422 + .../decorator/TFloatCharMapDecorator.java | 422 + .../decorator/TFloatDoubleMapDecorator.java | 423 + .../decorator/TFloatFloatMapDecorator.java | 422 + .../decorator/TFloatIntMapDecorator.java | 422 + .../trove/decorator/TFloatListDecorator.java | 137 + .../decorator/TFloatLongMapDecorator.java | 422 + .../decorator/TFloatObjectMapDecorator.java | 375 + .../trove/decorator/TFloatSetDecorator.java | 230 + .../decorator/TFloatShortMapDecorator.java | 422 + .../trove/decorator/TIntByteMapDecorator.java | 422 + .../trove/decorator/TIntCharMapDecorator.java | 422 + .../decorator/TIntDoubleMapDecorator.java | 422 + .../decorator/TIntFloatMapDecorator.java | 422 + .../trove/decorator/TIntIntMapDecorator.java | 422 + .../trove/decorator/TIntListDecorator.java | 137 + .../trove/decorator/TIntLongMapDecorator.java | 422 + .../decorator/TIntObjectMapDecorator.java | 374 + src/gnu/trove/decorator/TIntSetDecorator.java | 230 + .../decorator/TIntShortMapDecorator.java | 422 + .../decorator/TLongByteMapDecorator.java | 422 + .../decorator/TLongCharMapDecorator.java | 422 + .../decorator/TLongDoubleMapDecorator.java | 422 + .../decorator/TLongFloatMapDecorator.java | 422 + .../trove/decorator/TLongIntMapDecorator.java | 422 + .../trove/decorator/TLongListDecorator.java | 137 + .../decorator/TLongLongMapDecorator.java | 422 + .../decorator/TLongObjectMapDecorator.java | 374 + .../trove/decorator/TLongSetDecorator.java | 230 + .../decorator/TLongShortMapDecorator.java | 422 + .../decorator/TObjectByteMapDecorator.java | 365 + .../decorator/TObjectCharMapDecorator.java | 365 + .../decorator/TObjectDoubleMapDecorator.java | 367 + .../decorator/TObjectFloatMapDecorator.java | 366 + .../decorator/TObjectIntMapDecorator.java | 365 + .../decorator/TObjectLongMapDecorator.java | 365 + .../decorator/TObjectShortMapDecorator.java | 366 + .../decorator/TShortByteMapDecorator.java | 422 + .../decorator/TShortCharMapDecorator.java | 422 + .../decorator/TShortDoubleMapDecorator.java | 423 + .../decorator/TShortFloatMapDecorator.java | 422 + .../decorator/TShortIntMapDecorator.java | 422 + .../trove/decorator/TShortListDecorator.java | 137 + .../decorator/TShortLongMapDecorator.java | 422 + .../decorator/TShortObjectMapDecorator.java | 375 + .../trove/decorator/TShortSetDecorator.java | 230 + .../decorator/TShortShortMapDecorator.java | 422 + src/gnu/trove/function/TByteFunction.java | 38 + src/gnu/trove/function/TCharFunction.java | 38 + src/gnu/trove/function/TDoubleFunction.java | 38 + src/gnu/trove/function/TFloatFunction.java | 38 + src/gnu/trove/function/TIntFunction.java | 38 + src/gnu/trove/function/TLongFunction.java | 38 + src/gnu/trove/function/TObjectFunction.java | 41 + src/gnu/trove/function/TShortFunction.java | 38 + src/gnu/trove/impl/Constants.java | 227 + src/gnu/trove/impl/HashFunctions.java | 85 + src/gnu/trove/impl/PrimeFinder.java | 151 + src/gnu/trove/impl/hash/TByteByteHash.java | 458 + src/gnu/trove/impl/hash/TByteCharHash.java | 458 + src/gnu/trove/impl/hash/TByteDoubleHash.java | 458 + src/gnu/trove/impl/hash/TByteFloatHash.java | 458 + src/gnu/trove/impl/hash/TByteHash.java | 334 + src/gnu/trove/impl/hash/TByteIntHash.java | 458 + src/gnu/trove/impl/hash/TByteLongHash.java | 458 + src/gnu/trove/impl/hash/TByteShortHash.java | 458 + src/gnu/trove/impl/hash/TCharByteHash.java | 458 + src/gnu/trove/impl/hash/TCharCharHash.java | 458 + src/gnu/trove/impl/hash/TCharDoubleHash.java | 458 + src/gnu/trove/impl/hash/TCharFloatHash.java | 458 + src/gnu/trove/impl/hash/TCharHash.java | 334 + src/gnu/trove/impl/hash/TCharIntHash.java | 458 + src/gnu/trove/impl/hash/TCharLongHash.java | 458 + src/gnu/trove/impl/hash/TCharShortHash.java | 458 + .../trove/impl/hash/TCustomObjectHash.java | 125 + src/gnu/trove/impl/hash/TDoubleByteHash.java | 458 + src/gnu/trove/impl/hash/TDoubleCharHash.java | 458 + .../trove/impl/hash/TDoubleDoubleHash.java | 458 + src/gnu/trove/impl/hash/TDoubleFloatHash.java | 458 + src/gnu/trove/impl/hash/TDoubleHash.java | 334 + src/gnu/trove/impl/hash/TDoubleIntHash.java | 458 + src/gnu/trove/impl/hash/TDoubleLongHash.java | 458 + src/gnu/trove/impl/hash/TDoubleShortHash.java | 458 + src/gnu/trove/impl/hash/TFloatByteHash.java | 458 + src/gnu/trove/impl/hash/TFloatCharHash.java | 458 + src/gnu/trove/impl/hash/TFloatDoubleHash.java | 458 + src/gnu/trove/impl/hash/TFloatFloatHash.java | 458 + src/gnu/trove/impl/hash/TFloatHash.java | 334 + src/gnu/trove/impl/hash/TFloatIntHash.java | 458 + src/gnu/trove/impl/hash/TFloatLongHash.java | 458 + src/gnu/trove/impl/hash/TFloatShortHash.java | 458 + src/gnu/trove/impl/hash/THash.java | 406 + src/gnu/trove/impl/hash/THashIterator.java | 170 + .../impl/hash/THashPrimitiveIterator.java | 139 + src/gnu/trove/impl/hash/TIntByteHash.java | 458 + src/gnu/trove/impl/hash/TIntCharHash.java | 458 + src/gnu/trove/impl/hash/TIntDoubleHash.java | 458 + src/gnu/trove/impl/hash/TIntFloatHash.java | 458 + src/gnu/trove/impl/hash/TIntHash.java | 334 + src/gnu/trove/impl/hash/TIntIntHash.java | 458 + src/gnu/trove/impl/hash/TIntLongHash.java | 458 + src/gnu/trove/impl/hash/TIntShortHash.java | 458 + src/gnu/trove/impl/hash/TLongByteHash.java | 458 + src/gnu/trove/impl/hash/TLongCharHash.java | 458 + src/gnu/trove/impl/hash/TLongDoubleHash.java | 458 + src/gnu/trove/impl/hash/TLongFloatHash.java | 458 + src/gnu/trove/impl/hash/TLongHash.java | 334 + src/gnu/trove/impl/hash/TLongIntHash.java | 458 + src/gnu/trove/impl/hash/TLongLongHash.java | 458 + src/gnu/trove/impl/hash/TLongShortHash.java | 458 + src/gnu/trove/impl/hash/TObjectHash.java | 630 ++ src/gnu/trove/impl/hash/TPrimitiveHash.java | 134 + src/gnu/trove/impl/hash/TShortByteHash.java | 458 + src/gnu/trove/impl/hash/TShortCharHash.java | 458 + src/gnu/trove/impl/hash/TShortDoubleHash.java | 458 + src/gnu/trove/impl/hash/TShortFloatHash.java | 458 + src/gnu/trove/impl/hash/TShortHash.java | 334 + src/gnu/trove/impl/hash/TShortIntHash.java | 458 + src/gnu/trove/impl/hash/TShortLongHash.java | 458 + src/gnu/trove/impl/hash/TShortShortHash.java | 458 + src/gnu/trove/impl/package.html | 24 + .../impl/sync/SynchronizedCollection.java | 143 + src/gnu/trove/impl/sync/SynchronizedSet.java | 46 + .../impl/sync/TSynchronizedByteByteMap.java | 285 + .../impl/sync/TSynchronizedByteCharMap.java | 285 + .../sync/TSynchronizedByteCollection.java | 227 + .../impl/sync/TSynchronizedByteDoubleMap.java | 285 + .../impl/sync/TSynchronizedByteFloatMap.java | 285 + .../impl/sync/TSynchronizedByteIntMap.java | 285 + .../impl/sync/TSynchronizedByteList.java | 341 + .../impl/sync/TSynchronizedByteLongMap.java | 285 + .../impl/sync/TSynchronizedByteObjectMap.java | 260 + .../trove/impl/sync/TSynchronizedByteSet.java | 58 + .../impl/sync/TSynchronizedByteShortMap.java | 285 + .../impl/sync/TSynchronizedCharByteMap.java | 285 + .../impl/sync/TSynchronizedCharCharMap.java | 285 + .../sync/TSynchronizedCharCollection.java | 227 + .../impl/sync/TSynchronizedCharDoubleMap.java | 285 + .../impl/sync/TSynchronizedCharFloatMap.java | 285 + .../impl/sync/TSynchronizedCharIntMap.java | 285 + .../impl/sync/TSynchronizedCharList.java | 341 + .../impl/sync/TSynchronizedCharLongMap.java | 285 + .../impl/sync/TSynchronizedCharObjectMap.java | 260 + .../trove/impl/sync/TSynchronizedCharSet.java | 58 + .../impl/sync/TSynchronizedCharShortMap.java | 285 + .../impl/sync/TSynchronizedDoubleByteMap.java | 285 + .../impl/sync/TSynchronizedDoubleCharMap.java | 285 + .../sync/TSynchronizedDoubleCollection.java | 227 + .../sync/TSynchronizedDoubleDoubleMap.java | 285 + .../sync/TSynchronizedDoubleFloatMap.java | 285 + .../impl/sync/TSynchronizedDoubleIntMap.java | 285 + .../impl/sync/TSynchronizedDoubleList.java | 341 + .../impl/sync/TSynchronizedDoubleLongMap.java | 285 + .../sync/TSynchronizedDoubleObjectMap.java | 260 + .../impl/sync/TSynchronizedDoubleSet.java | 58 + .../sync/TSynchronizedDoubleShortMap.java | 285 + .../impl/sync/TSynchronizedFloatByteMap.java | 285 + .../impl/sync/TSynchronizedFloatCharMap.java | 285 + .../sync/TSynchronizedFloatCollection.java | 227 + .../sync/TSynchronizedFloatDoubleMap.java | 285 + .../impl/sync/TSynchronizedFloatFloatMap.java | 285 + .../impl/sync/TSynchronizedFloatIntMap.java | 285 + .../impl/sync/TSynchronizedFloatList.java | 341 + .../impl/sync/TSynchronizedFloatLongMap.java | 285 + .../sync/TSynchronizedFloatObjectMap.java | 260 + .../impl/sync/TSynchronizedFloatSet.java | 58 + .../impl/sync/TSynchronizedFloatShortMap.java | 285 + .../impl/sync/TSynchronizedIntByteMap.java | 285 + .../impl/sync/TSynchronizedIntCharMap.java | 285 + .../impl/sync/TSynchronizedIntCollection.java | 227 + .../impl/sync/TSynchronizedIntDoubleMap.java | 285 + .../impl/sync/TSynchronizedIntFloatMap.java | 285 + .../impl/sync/TSynchronizedIntIntMap.java | 285 + .../trove/impl/sync/TSynchronizedIntList.java | 341 + .../impl/sync/TSynchronizedIntLongMap.java | 285 + .../impl/sync/TSynchronizedIntObjectMap.java | 260 + .../trove/impl/sync/TSynchronizedIntSet.java | 58 + .../impl/sync/TSynchronizedIntShortMap.java | 285 + .../impl/sync/TSynchronizedLongByteMap.java | 285 + .../impl/sync/TSynchronizedLongCharMap.java | 285 + .../sync/TSynchronizedLongCollection.java | 227 + .../impl/sync/TSynchronizedLongDoubleMap.java | 285 + .../impl/sync/TSynchronizedLongFloatMap.java | 285 + .../impl/sync/TSynchronizedLongIntMap.java | 285 + .../impl/sync/TSynchronizedLongList.java | 341 + .../impl/sync/TSynchronizedLongLongMap.java | 285 + .../impl/sync/TSynchronizedLongObjectMap.java | 260 + .../trove/impl/sync/TSynchronizedLongSet.java | 58 + .../impl/sync/TSynchronizedLongShortMap.java | 285 + .../impl/sync/TSynchronizedObjectByteMap.java | 281 + .../impl/sync/TSynchronizedObjectCharMap.java | 281 + .../sync/TSynchronizedObjectDoubleMap.java | 281 + .../sync/TSynchronizedObjectFloatMap.java | 281 + .../impl/sync/TSynchronizedObjectIntMap.java | 281 + .../impl/sync/TSynchronizedObjectLongMap.java | 281 + .../sync/TSynchronizedObjectShortMap.java | 281 + .../TSynchronizedRandomAccessByteList.java | 61 + .../TSynchronizedRandomAccessCharList.java | 61 + .../TSynchronizedRandomAccessDoubleList.java | 61 + .../TSynchronizedRandomAccessFloatList.java | 61 + .../TSynchronizedRandomAccessIntList.java | 61 + .../TSynchronizedRandomAccessLongList.java | 61 + .../TSynchronizedRandomAccessShortList.java | 61 + .../impl/sync/TSynchronizedShortByteMap.java | 285 + .../impl/sync/TSynchronizedShortCharMap.java | 285 + .../sync/TSynchronizedShortCollection.java | 227 + .../sync/TSynchronizedShortDoubleMap.java | 285 + .../impl/sync/TSynchronizedShortFloatMap.java | 285 + .../impl/sync/TSynchronizedShortIntMap.java | 285 + .../impl/sync/TSynchronizedShortList.java | 341 + .../impl/sync/TSynchronizedShortLongMap.java | 285 + .../sync/TSynchronizedShortObjectMap.java | 260 + .../impl/sync/TSynchronizedShortSet.java | 58 + .../impl/sync/TSynchronizedShortShortMap.java | 285 + .../TUnmodifiableByteByteMap.java | 245 + .../TUnmodifiableByteCharMap.java | 245 + .../TUnmodifiableByteCollection.java | 185 + .../TUnmodifiableByteDoubleMap.java | 245 + .../TUnmodifiableByteFloatMap.java | 245 + .../unmodifiable/TUnmodifiableByteIntMap.java | 245 + .../unmodifiable/TUnmodifiableByteList.java | 277 + .../TUnmodifiableByteLongMap.java | 245 + .../TUnmodifiableByteObjectMap.java | 225 + .../unmodifiable/TUnmodifiableByteSet.java | 51 + .../TUnmodifiableByteShortMap.java | 245 + .../TUnmodifiableCharByteMap.java | 245 + .../TUnmodifiableCharCharMap.java | 245 + .../TUnmodifiableCharCollection.java | 185 + .../TUnmodifiableCharDoubleMap.java | 245 + .../TUnmodifiableCharFloatMap.java | 245 + .../unmodifiable/TUnmodifiableCharIntMap.java | 245 + .../unmodifiable/TUnmodifiableCharList.java | 277 + .../TUnmodifiableCharLongMap.java | 245 + .../TUnmodifiableCharObjectMap.java | 225 + .../unmodifiable/TUnmodifiableCharSet.java | 51 + .../TUnmodifiableCharShortMap.java | 245 + .../TUnmodifiableDoubleByteMap.java | 245 + .../TUnmodifiableDoubleCharMap.java | 245 + .../TUnmodifiableDoubleCollection.java | 185 + .../TUnmodifiableDoubleDoubleMap.java | 245 + .../TUnmodifiableDoubleFloatMap.java | 245 + .../TUnmodifiableDoubleIntMap.java | 245 + .../unmodifiable/TUnmodifiableDoubleList.java | 277 + .../TUnmodifiableDoubleLongMap.java | 245 + .../TUnmodifiableDoubleObjectMap.java | 225 + .../unmodifiable/TUnmodifiableDoubleSet.java | 51 + .../TUnmodifiableDoubleShortMap.java | 245 + .../TUnmodifiableFloatByteMap.java | 245 + .../TUnmodifiableFloatCharMap.java | 245 + .../TUnmodifiableFloatCollection.java | 185 + .../TUnmodifiableFloatDoubleMap.java | 245 + .../TUnmodifiableFloatFloatMap.java | 245 + .../TUnmodifiableFloatIntMap.java | 245 + .../unmodifiable/TUnmodifiableFloatList.java | 277 + .../TUnmodifiableFloatLongMap.java | 245 + .../TUnmodifiableFloatObjectMap.java | 225 + .../unmodifiable/TUnmodifiableFloatSet.java | 51 + .../TUnmodifiableFloatShortMap.java | 245 + .../unmodifiable/TUnmodifiableIntByteMap.java | 245 + .../unmodifiable/TUnmodifiableIntCharMap.java | 245 + .../TUnmodifiableIntCollection.java | 185 + .../TUnmodifiableIntDoubleMap.java | 245 + .../TUnmodifiableIntFloatMap.java | 245 + .../unmodifiable/TUnmodifiableIntIntMap.java | 245 + .../unmodifiable/TUnmodifiableIntList.java | 277 + .../unmodifiable/TUnmodifiableIntLongMap.java | 245 + .../TUnmodifiableIntObjectMap.java | 225 + .../unmodifiable/TUnmodifiableIntSet.java | 51 + .../TUnmodifiableIntShortMap.java | 245 + .../TUnmodifiableLongByteMap.java | 245 + .../TUnmodifiableLongCharMap.java | 245 + .../TUnmodifiableLongCollection.java | 185 + .../TUnmodifiableLongDoubleMap.java | 245 + .../TUnmodifiableLongFloatMap.java | 245 + .../unmodifiable/TUnmodifiableLongIntMap.java | 245 + .../unmodifiable/TUnmodifiableLongList.java | 277 + .../TUnmodifiableLongLongMap.java | 245 + .../TUnmodifiableLongObjectMap.java | 225 + .../unmodifiable/TUnmodifiableLongSet.java | 51 + .../TUnmodifiableLongShortMap.java | 245 + .../TUnmodifiableObjectByteMap.java | 239 + .../TUnmodifiableObjectCharMap.java | 239 + .../TUnmodifiableObjectDoubleMap.java | 239 + .../TUnmodifiableObjectFloatMap.java | 239 + .../TUnmodifiableObjectIntMap.java | 239 + .../TUnmodifiableObjectLongMap.java | 239 + .../TUnmodifiableObjectShortMap.java | 239 + .../TUnmodifiableRandomAccessByteList.java | 55 + .../TUnmodifiableRandomAccessCharList.java | 55 + .../TUnmodifiableRandomAccessDoubleList.java | 55 + .../TUnmodifiableRandomAccessFloatList.java | 55 + .../TUnmodifiableRandomAccessIntList.java | 55 + .../TUnmodifiableRandomAccessLongList.java | 55 + .../TUnmodifiableRandomAccessShortList.java | 55 + .../TUnmodifiableShortByteMap.java | 245 + .../TUnmodifiableShortCharMap.java | 245 + .../TUnmodifiableShortCollection.java | 185 + .../TUnmodifiableShortDoubleMap.java | 245 + .../TUnmodifiableShortFloatMap.java | 245 + .../TUnmodifiableShortIntMap.java | 245 + .../unmodifiable/TUnmodifiableShortList.java | 277 + .../TUnmodifiableShortLongMap.java | 245 + .../TUnmodifiableShortObjectMap.java | 225 + .../unmodifiable/TUnmodifiableShortSet.java | 51 + .../TUnmodifiableShortShortMap.java | 245 + .../trove/iterator/TAdvancingIterator.java | 32 + src/gnu/trove/iterator/TByteByteIterator.java | 124 + src/gnu/trove/iterator/TByteCharIterator.java | 124 + .../trove/iterator/TByteDoubleIterator.java | 124 + .../trove/iterator/TByteFloatIterator.java | 124 + src/gnu/trove/iterator/TByteIntIterator.java | 124 + src/gnu/trove/iterator/TByteIterator.java | 39 + src/gnu/trove/iterator/TByteLongIterator.java | 124 + .../trove/iterator/TByteObjectIterator.java | 129 + .../trove/iterator/TByteShortIterator.java | 124 + src/gnu/trove/iterator/TCharByteIterator.java | 124 + src/gnu/trove/iterator/TCharCharIterator.java | 124 + .../trove/iterator/TCharDoubleIterator.java | 124 + .../trove/iterator/TCharFloatIterator.java | 124 + src/gnu/trove/iterator/TCharIntIterator.java | 124 + src/gnu/trove/iterator/TCharIterator.java | 39 + src/gnu/trove/iterator/TCharLongIterator.java | 124 + .../trove/iterator/TCharObjectIterator.java | 129 + .../trove/iterator/TCharShortIterator.java | 124 + .../trove/iterator/TDoubleByteIterator.java | 124 + .../trove/iterator/TDoubleCharIterator.java | 124 + .../trove/iterator/TDoubleDoubleIterator.java | 124 + .../trove/iterator/TDoubleFloatIterator.java | 124 + .../trove/iterator/TDoubleIntIterator.java | 124 + src/gnu/trove/iterator/TDoubleIterator.java | 39 + .../trove/iterator/TDoubleLongIterator.java | 124 + .../trove/iterator/TDoubleObjectIterator.java | 129 + .../trove/iterator/TDoubleShortIterator.java | 124 + .../trove/iterator/TFloatByteIterator.java | 124 + .../trove/iterator/TFloatCharIterator.java | 124 + .../trove/iterator/TFloatDoubleIterator.java | 124 + .../trove/iterator/TFloatFloatIterator.java | 124 + src/gnu/trove/iterator/TFloatIntIterator.java | 124 + src/gnu/trove/iterator/TFloatIterator.java | 39 + .../trove/iterator/TFloatLongIterator.java | 124 + .../trove/iterator/TFloatObjectIterator.java | 129 + .../trove/iterator/TFloatShortIterator.java | 124 + src/gnu/trove/iterator/TIntByteIterator.java | 124 + src/gnu/trove/iterator/TIntCharIterator.java | 124 + .../trove/iterator/TIntDoubleIterator.java | 124 + src/gnu/trove/iterator/TIntFloatIterator.java | 124 + src/gnu/trove/iterator/TIntIntIterator.java | 124 + src/gnu/trove/iterator/TIntIterator.java | 39 + src/gnu/trove/iterator/TIntLongIterator.java | 124 + .../trove/iterator/TIntObjectIterator.java | 129 + src/gnu/trove/iterator/TIntShortIterator.java | 124 + src/gnu/trove/iterator/TIterator.java | 37 + src/gnu/trove/iterator/TLongByteIterator.java | 124 + src/gnu/trove/iterator/TLongCharIterator.java | 124 + .../trove/iterator/TLongDoubleIterator.java | 124 + .../trove/iterator/TLongFloatIterator.java | 124 + src/gnu/trove/iterator/TLongIntIterator.java | 124 + src/gnu/trove/iterator/TLongIterator.java | 39 + src/gnu/trove/iterator/TLongLongIterator.java | 124 + .../trove/iterator/TLongObjectIterator.java | 129 + .../trove/iterator/TLongShortIterator.java | 124 + .../trove/iterator/TObjectByteIterator.java | 129 + .../trove/iterator/TObjectCharIterator.java | 129 + .../trove/iterator/TObjectDoubleIterator.java | 129 + .../trove/iterator/TObjectFloatIterator.java | 129 + .../trove/iterator/TObjectIntIterator.java | 129 + .../trove/iterator/TObjectLongIterator.java | 129 + .../trove/iterator/TObjectShortIterator.java | 129 + .../trove/iterator/TPrimitiveIterator.java | 63 + .../trove/iterator/TShortByteIterator.java | 124 + .../trove/iterator/TShortCharIterator.java | 124 + .../trove/iterator/TShortDoubleIterator.java | 124 + .../trove/iterator/TShortFloatIterator.java | 124 + src/gnu/trove/iterator/TShortIntIterator.java | 124 + src/gnu/trove/iterator/TShortIterator.java | 39 + .../trove/iterator/TShortLongIterator.java | 124 + .../trove/iterator/TShortObjectIterator.java | 129 + .../trove/iterator/TShortShortIterator.java | 124 + .../iterator/hash/TObjectHashIterator.java | 55 + src/gnu/trove/list/TByteList.java | 530 ++ src/gnu/trove/list/TCharList.java | 530 ++ src/gnu/trove/list/TDoubleList.java | 530 ++ src/gnu/trove/list/TFloatList.java | 530 ++ src/gnu/trove/list/TIntList.java | 530 ++ src/gnu/trove/list/TLinkable.java | 64 + src/gnu/trove/list/TLinkableAdapter.java | 44 + src/gnu/trove/list/TLongList.java | 530 ++ src/gnu/trove/list/TShortList.java | 530 ++ src/gnu/trove/list/array/TByteArrayList.java | 1072 +++ src/gnu/trove/list/array/TCharArrayList.java | 1072 +++ .../trove/list/array/TDoubleArrayList.java | 1073 +++ src/gnu/trove/list/array/TFloatArrayList.java | 1073 +++ src/gnu/trove/list/array/TIntArrayList.java | 1072 +++ src/gnu/trove/list/array/TLongArrayList.java | 1072 +++ src/gnu/trove/list/array/TShortArrayList.java | 1073 +++ .../trove/list/linked/TByteLinkedList.java | 1118 +++ .../trove/list/linked/TCharLinkedList.java | 1118 +++ .../trove/list/linked/TDoubleLinkedList.java | 1118 +++ .../trove/list/linked/TFloatLinkedList.java | 1118 +++ src/gnu/trove/list/linked/TIntLinkedList.java | 1118 +++ src/gnu/trove/list/linked/TLinkedList.java | 849 ++ .../trove/list/linked/TLongLinkedList.java | 1118 +++ .../trove/list/linked/TShortLinkedList.java | 1118 +++ src/gnu/trove/map/TByteByteMap.java | 294 + src/gnu/trove/map/TByteCharMap.java | 294 + src/gnu/trove/map/TByteDoubleMap.java | 294 + src/gnu/trove/map/TByteFloatMap.java | 294 + src/gnu/trove/map/TByteIntMap.java | 294 + src/gnu/trove/map/TByteLongMap.java | 294 + src/gnu/trove/map/TByteObjectMap.java | 424 + src/gnu/trove/map/TByteShortMap.java | 294 + src/gnu/trove/map/TCharByteMap.java | 294 + src/gnu/trove/map/TCharCharMap.java | 294 + src/gnu/trove/map/TCharDoubleMap.java | 294 + src/gnu/trove/map/TCharFloatMap.java | 294 + src/gnu/trove/map/TCharIntMap.java | 294 + src/gnu/trove/map/TCharLongMap.java | 294 + src/gnu/trove/map/TCharObjectMap.java | 424 + src/gnu/trove/map/TCharShortMap.java | 294 + src/gnu/trove/map/TDoubleByteMap.java | 294 + src/gnu/trove/map/TDoubleCharMap.java | 294 + src/gnu/trove/map/TDoubleDoubleMap.java | 294 + src/gnu/trove/map/TDoubleFloatMap.java | 294 + src/gnu/trove/map/TDoubleIntMap.java | 294 + src/gnu/trove/map/TDoubleLongMap.java | 294 + src/gnu/trove/map/TDoubleObjectMap.java | 424 + src/gnu/trove/map/TDoubleShortMap.java | 294 + src/gnu/trove/map/TFloatByteMap.java | 294 + src/gnu/trove/map/TFloatCharMap.java | 294 + src/gnu/trove/map/TFloatDoubleMap.java | 294 + src/gnu/trove/map/TFloatFloatMap.java | 294 + src/gnu/trove/map/TFloatIntMap.java | 294 + src/gnu/trove/map/TFloatLongMap.java | 294 + src/gnu/trove/map/TFloatObjectMap.java | 424 + src/gnu/trove/map/TFloatShortMap.java | 294 + src/gnu/trove/map/TIntByteMap.java | 294 + src/gnu/trove/map/TIntCharMap.java | 294 + src/gnu/trove/map/TIntDoubleMap.java | 294 + src/gnu/trove/map/TIntFloatMap.java | 294 + src/gnu/trove/map/TIntIntMap.java | 294 + src/gnu/trove/map/TIntLongMap.java | 294 + src/gnu/trove/map/TIntObjectMap.java | 424 + src/gnu/trove/map/TIntShortMap.java | 294 + src/gnu/trove/map/TLongByteMap.java | 294 + src/gnu/trove/map/TLongCharMap.java | 294 + src/gnu/trove/map/TLongDoubleMap.java | 294 + src/gnu/trove/map/TLongFloatMap.java | 294 + src/gnu/trove/map/TLongIntMap.java | 294 + src/gnu/trove/map/TLongLongMap.java | 294 + src/gnu/trove/map/TLongObjectMap.java | 424 + src/gnu/trove/map/TLongShortMap.java | 294 + src/gnu/trove/map/TMap.java | 95 + src/gnu/trove/map/TObjectByteMap.java | 462 + src/gnu/trove/map/TObjectCharMap.java | 462 + src/gnu/trove/map/TObjectDoubleMap.java | 462 + src/gnu/trove/map/TObjectFloatMap.java | 462 + src/gnu/trove/map/TObjectIntMap.java | 462 + src/gnu/trove/map/TObjectLongMap.java | 462 + src/gnu/trove/map/TObjectShortMap.java | 462 + src/gnu/trove/map/TShortByteMap.java | 294 + src/gnu/trove/map/TShortCharMap.java | 294 + src/gnu/trove/map/TShortDoubleMap.java | 294 + src/gnu/trove/map/TShortFloatMap.java | 294 + src/gnu/trove/map/TShortIntMap.java | 294 + src/gnu/trove/map/TShortLongMap.java | 294 + src/gnu/trove/map/TShortObjectMap.java | 424 + src/gnu/trove/map/TShortShortMap.java | 294 + .../custom_hash/TObjectByteCustomHashMap.java | 1185 +++ .../custom_hash/TObjectCharCustomHashMap.java | 1185 +++ .../TObjectDoubleCustomHashMap.java | 1185 +++ .../TObjectFloatCustomHashMap.java | 1185 +++ .../custom_hash/TObjectIntCustomHashMap.java | 1185 +++ .../custom_hash/TObjectLongCustomHashMap.java | 1185 +++ .../TObjectShortCustomHashMap.java | 1185 +++ src/gnu/trove/map/hash/TByteByteHashMap.java | 1303 +++ src/gnu/trove/map/hash/TByteCharHashMap.java | 1303 +++ .../trove/map/hash/TByteDoubleHashMap.java | 1303 +++ src/gnu/trove/map/hash/TByteFloatHashMap.java | 1303 +++ src/gnu/trove/map/hash/TByteIntHashMap.java | 1303 +++ src/gnu/trove/map/hash/TByteLongHashMap.java | 1303 +++ .../trove/map/hash/TByteObjectHashMap.java | 1060 +++ src/gnu/trove/map/hash/TByteShortHashMap.java | 1303 +++ src/gnu/trove/map/hash/TCharByteHashMap.java | 1303 +++ src/gnu/trove/map/hash/TCharCharHashMap.java | 1303 +++ .../trove/map/hash/TCharDoubleHashMap.java | 1303 +++ src/gnu/trove/map/hash/TCharFloatHashMap.java | 1303 +++ src/gnu/trove/map/hash/TCharIntHashMap.java | 1303 +++ src/gnu/trove/map/hash/TCharLongHashMap.java | 1303 +++ .../trove/map/hash/TCharObjectHashMap.java | 1060 +++ src/gnu/trove/map/hash/TCharShortHashMap.java | 1303 +++ src/gnu/trove/map/hash/TCustomHashMap.java | 896 ++ .../trove/map/hash/TDoubleByteHashMap.java | 1304 +++ .../trove/map/hash/TDoubleCharHashMap.java | 1304 +++ .../trove/map/hash/TDoubleDoubleHashMap.java | 1304 +++ .../trove/map/hash/TDoubleFloatHashMap.java | 1304 +++ src/gnu/trove/map/hash/TDoubleIntHashMap.java | 1304 +++ .../trove/map/hash/TDoubleLongHashMap.java | 1304 +++ .../trove/map/hash/TDoubleObjectHashMap.java | 1060 +++ .../trove/map/hash/TDoubleShortHashMap.java | 1304 +++ src/gnu/trove/map/hash/TFloatByteHashMap.java | 1304 +++ src/gnu/trove/map/hash/TFloatCharHashMap.java | 1304 +++ .../trove/map/hash/TFloatDoubleHashMap.java | 1304 +++ .../trove/map/hash/TFloatFloatHashMap.java | 1304 +++ src/gnu/trove/map/hash/TFloatIntHashMap.java | 1304 +++ src/gnu/trove/map/hash/TFloatLongHashMap.java | 1304 +++ .../trove/map/hash/TFloatObjectHashMap.java | 1060 +++ .../trove/map/hash/TFloatShortHashMap.java | 1304 +++ src/gnu/trove/map/hash/THashMap.java | 914 ++ src/gnu/trove/map/hash/TIntByteHashMap.java | 1303 +++ src/gnu/trove/map/hash/TIntCharHashMap.java | 1303 +++ src/gnu/trove/map/hash/TIntDoubleHashMap.java | 1303 +++ src/gnu/trove/map/hash/TIntFloatHashMap.java | 1303 +++ src/gnu/trove/map/hash/TIntIntHashMap.java | 1303 +++ src/gnu/trove/map/hash/TIntLongHashMap.java | 1303 +++ src/gnu/trove/map/hash/TIntObjectHashMap.java | 1000 +++ src/gnu/trove/map/hash/TIntShortHashMap.java | 1303 +++ src/gnu/trove/map/hash/TLongByteHashMap.java | 1303 +++ src/gnu/trove/map/hash/TLongCharHashMap.java | 1303 +++ .../trove/map/hash/TLongDoubleHashMap.java | 1303 +++ src/gnu/trove/map/hash/TLongFloatHashMap.java | 1303 +++ src/gnu/trove/map/hash/TLongIntHashMap.java | 1303 +++ src/gnu/trove/map/hash/TLongLongHashMap.java | 1303 +++ .../trove/map/hash/TLongObjectHashMap.java | 1000 +++ src/gnu/trove/map/hash/TLongShortHashMap.java | 1303 +++ .../trove/map/hash/TObjectByteHashMap.java | 1170 +++ .../trove/map/hash/TObjectCharHashMap.java | 1170 +++ .../trove/map/hash/TObjectDoubleHashMap.java | 1170 +++ .../trove/map/hash/TObjectFloatHashMap.java | 1170 +++ src/gnu/trove/map/hash/TObjectIntHashMap.java | 1170 +++ .../trove/map/hash/TObjectLongHashMap.java | 1170 +++ .../trove/map/hash/TObjectShortHashMap.java | 1170 +++ src/gnu/trove/map/hash/TShortByteHashMap.java | 1304 +++ src/gnu/trove/map/hash/TShortCharHashMap.java | 1304 +++ .../trove/map/hash/TShortDoubleHashMap.java | 1304 +++ .../trove/map/hash/TShortFloatHashMap.java | 1304 +++ src/gnu/trove/map/hash/TShortIntHashMap.java | 1304 +++ src/gnu/trove/map/hash/TShortLongHashMap.java | 1304 +++ .../trove/map/hash/TShortObjectHashMap.java | 1060 +++ .../trove/map/hash/TShortShortHashMap.java | 1304 +++ .../trove/procedure/TByteByteProcedure.java | 42 + .../trove/procedure/TByteCharProcedure.java | 42 + .../trove/procedure/TByteDoubleProcedure.java | 42 + .../trove/procedure/TByteFloatProcedure.java | 42 + .../trove/procedure/TByteIntProcedure.java | 42 + .../trove/procedure/TByteLongProcedure.java | 42 + .../trove/procedure/TByteObjectProcedure.java | 42 + src/gnu/trove/procedure/TByteProcedure.java | 38 + .../trove/procedure/TByteShortProcedure.java | 42 + .../trove/procedure/TCharByteProcedure.java | 42 + .../trove/procedure/TCharCharProcedure.java | 42 + .../trove/procedure/TCharDoubleProcedure.java | 42 + .../trove/procedure/TCharFloatProcedure.java | 42 + .../trove/procedure/TCharIntProcedure.java | 42 + .../trove/procedure/TCharLongProcedure.java | 42 + .../trove/procedure/TCharObjectProcedure.java | 42 + src/gnu/trove/procedure/TCharProcedure.java | 38 + .../trove/procedure/TCharShortProcedure.java | 42 + .../trove/procedure/TDoubleByteProcedure.java | 42 + .../trove/procedure/TDoubleCharProcedure.java | 42 + .../procedure/TDoubleDoubleProcedure.java | 42 + .../procedure/TDoubleFloatProcedure.java | 42 + .../trove/procedure/TDoubleIntProcedure.java | 42 + .../trove/procedure/TDoubleLongProcedure.java | 42 + .../procedure/TDoubleObjectProcedure.java | 42 + src/gnu/trove/procedure/TDoubleProcedure.java | 38 + .../procedure/TDoubleShortProcedure.java | 42 + .../trove/procedure/TFloatByteProcedure.java | 42 + .../trove/procedure/TFloatCharProcedure.java | 42 + .../procedure/TFloatDoubleProcedure.java | 42 + .../trove/procedure/TFloatFloatProcedure.java | 42 + .../trove/procedure/TFloatIntProcedure.java | 42 + .../trove/procedure/TFloatLongProcedure.java | 42 + .../procedure/TFloatObjectProcedure.java | 42 + src/gnu/trove/procedure/TFloatProcedure.java | 38 + .../trove/procedure/TFloatShortProcedure.java | 42 + .../trove/procedure/TIntByteProcedure.java | 42 + .../trove/procedure/TIntCharProcedure.java | 42 + .../trove/procedure/TIntDoubleProcedure.java | 42 + .../trove/procedure/TIntFloatProcedure.java | 42 + src/gnu/trove/procedure/TIntIntProcedure.java | 42 + .../trove/procedure/TIntLongProcedure.java | 42 + .../trove/procedure/TIntObjectProcedure.java | 42 + src/gnu/trove/procedure/TIntProcedure.java | 38 + .../trove/procedure/TIntShortProcedure.java | 42 + .../trove/procedure/TLongByteProcedure.java | 42 + .../trove/procedure/TLongCharProcedure.java | 42 + .../trove/procedure/TLongDoubleProcedure.java | 42 + .../trove/procedure/TLongFloatProcedure.java | 42 + .../trove/procedure/TLongIntProcedure.java | 42 + .../trove/procedure/TLongLongProcedure.java | 42 + .../trove/procedure/TLongObjectProcedure.java | 42 + src/gnu/trove/procedure/TLongProcedure.java | 38 + .../trove/procedure/TLongShortProcedure.java | 42 + .../trove/procedure/TObjectByteProcedure.java | 42 + .../trove/procedure/TObjectCharProcedure.java | 42 + .../procedure/TObjectDoubleProcedure.java | 42 + .../procedure/TObjectFloatProcedure.java | 42 + .../trove/procedure/TObjectIntProcedure.java | 42 + .../trove/procedure/TObjectLongProcedure.java | 42 + .../procedure/TObjectObjectProcedure.java | 44 + src/gnu/trove/procedure/TObjectProcedure.java | 41 + .../procedure/TObjectShortProcedure.java | 42 + .../trove/procedure/TShortByteProcedure.java | 42 + .../trove/procedure/TShortCharProcedure.java | 42 + .../procedure/TShortDoubleProcedure.java | 42 + .../trove/procedure/TShortFloatProcedure.java | 42 + .../trove/procedure/TShortIntProcedure.java | 42 + .../trove/procedure/TShortLongProcedure.java | 42 + .../procedure/TShortObjectProcedure.java | 42 + src/gnu/trove/procedure/TShortProcedure.java | 38 + .../trove/procedure/TShortShortProcedure.java | 42 + .../array/ToObjectArrayProceedure.java | 47 + src/gnu/trove/queue/TByteQueue.java | 67 + src/gnu/trove/queue/TCharQueue.java | 67 + src/gnu/trove/queue/TDoubleQueue.java | 67 + src/gnu/trove/queue/TFloatQueue.java | 67 + src/gnu/trove/queue/TIntQueue.java | 67 + src/gnu/trove/queue/TLongQueue.java | 67 + src/gnu/trove/queue/TShortQueue.java | 67 + src/gnu/trove/set/TByteSet.java | 331 + src/gnu/trove/set/TCharSet.java | 331 + src/gnu/trove/set/TDoubleSet.java | 331 + src/gnu/trove/set/TFloatSet.java | 331 + src/gnu/trove/set/TIntSet.java | 331 + src/gnu/trove/set/TLongSet.java | 331 + src/gnu/trove/set/TShortSet.java | 331 + src/gnu/trove/set/hash/TByteHashSet.java | 551 ++ src/gnu/trove/set/hash/TCharHashSet.java | 551 ++ src/gnu/trove/set/hash/TCustomHashSet.java | 411 + src/gnu/trove/set/hash/TDoubleHashSet.java | 552 ++ src/gnu/trove/set/hash/TFloatHashSet.java | 551 ++ src/gnu/trove/set/hash/THashSet.java | 418 + src/gnu/trove/set/hash/TIntHashSet.java | 551 ++ src/gnu/trove/set/hash/TLinkedHashSet.java | 320 + src/gnu/trove/set/hash/TLongHashSet.java | 551 ++ src/gnu/trove/set/hash/TShortHashSet.java | 551 ++ src/gnu/trove/stack/TByteStack.java | 89 + src/gnu/trove/stack/TCharStack.java | 89 + src/gnu/trove/stack/TDoubleStack.java | 89 + src/gnu/trove/stack/TFloatStack.java | 89 + src/gnu/trove/stack/TIntStack.java | 89 + src/gnu/trove/stack/TLongStack.java | 89 + src/gnu/trove/stack/TShortStack.java | 89 + .../trove/stack/array/TByteArrayStack.java | 288 + .../trove/stack/array/TCharArrayStack.java | 288 + .../trove/stack/array/TDoubleArrayStack.java | 288 + .../trove/stack/array/TFloatArrayStack.java | 288 + src/gnu/trove/stack/array/TIntArrayStack.java | 287 + .../trove/stack/array/TLongArrayStack.java | 288 + .../trove/stack/array/TShortArrayStack.java | 288 + src/gnu/trove/strategy/HashingStrategy.java | 59 + .../strategy/IdentityHashingStrategy.java | 26 + src/me/Utils.java | 70 + src/me/bruce/factions/KIts/GiveBook.java | 33 + src/me/bruce/factions/KIts/KitsBook.java | 73 + src/me/bruce/factions/KIts/KitsInteract.java | 37 + src/me/bruce/factions/KIts/KitsInvClick.java | 55 + .../factions/KIts/Kitsgive/GiveKits.java | 187 + src/me/bruce/factions/LorexHCF.java | 722 ++ src/me/bruce/factions/armors/PvpClass.java | 83 + .../factions/armors/PvpClassManager.java | 103 + .../factions/armors/archer/ArcherClass.java | 217 + .../factions/armors/archer/ArcherMark.java | 52 + .../bruce/factions/armors/bard/BardClass.java | 364 + .../bruce/factions/armors/bard/BardData.java | 68 + .../factions/armors/bard/BardEffect.java | 16 + .../factions/armors/bard/EffectRestorer.java | 68 + .../armors/event/PvpClassEquipEvent.java | 40 + .../armors/event/PvpClassUnequipEvent.java | 40 + .../factions/armors/miner/MinerClass.java | 141 + .../factions/armors/rogue/RogueClass.java | 84 + src/me/bruce/factions/commands/.DS_Store | Bin 0 -> 6148 bytes .../bruce/factions/commands/BallerRevive.java | 63 + .../bruce/factions/commands/BanCommand.java | 34 + .../factions/commands/BroadCastCommand.java | 35 + src/me/bruce/factions/commands/Buy.java | 22 + .../factions/commands/CobbleCommand.java | 56 + .../factions/commands/CoordsCommand.java | 33 + src/me/bruce/factions/commands/Discord.java | 5 + src/me/bruce/factions/commands/FRCOMMAND.java | 39 + .../bruce/factions/commands/FixCommand.java | 57 + src/me/bruce/factions/commands/Forums.java | 5 + .../factions/commands/FreezeCommand.java | 229 + .../factions/commands/GiveCrowbarCommand.java | 37 + .../factions/commands/GlowstoneMountain.java | 28 + .../factions/commands/GoppleCommand.java | 57 + .../bruce/factions/commands/HelpCommand.java | 76 + .../bruce/factions/commands/HubCommand.java | 57 + .../factions/commands/InveeSeeCommand.java | 122 + .../bruce/factions/commands/LFFCommand.java | 50 + .../factions/commands/LogoutCommand.java | 49 + .../factions/commands/MapKitCommand.java | 82 + .../bruce/factions/commands/MedicCommand.java | 95 + .../bruce/factions/commands/OresCommand.java | 96 + src/me/bruce/factions/commands/Panic.java | 41 + .../bruce/factions/commands/PingCommand.java | 32 + .../factions/commands/PlayTimeCommand.java | 47 + .../bruce/factions/commands/PotsCommand.java | 136 + src/me/bruce/factions/commands/Pro.java | 66 + .../bruce/factions/commands/PvPCommand.java | 98 + .../factions/commands/RefundCommand.java | 92 + .../bruce/factions/commands/RegenCommand.java | 83 + .../factions/commands/RenameCommand.java | 58 + .../factions/commands/ReviveCommand.java | 73 + .../bruce/factions/commands/RulesCommand.java | 26 + src/me/bruce/factions/commands/SPCOMMAND.java | 39 + .../factions/commands/SetPrefixCommand.java | 43 + .../factions/commands/SettingsCommand.java | 264 + .../bruce/factions/commands/SpawnCommand.java | 42 + .../factions/commands/StaffInformation.java | 30 + .../factions/commands/StaffSettings.java | 113 + .../bruce/factions/commands/StatsCommand.java | 31 + src/me/bruce/factions/commands/Store.java | 5 + src/me/bruce/factions/commands/TLCommand.java | 27 + src/me/bruce/factions/commands/Tablist.java | 55 + .../factions/commands/TablistCommand.java | 74 + .../commands/ToggleCapzoneEntryCommand.java | 49 + .../commands/ToggleLightningCommand.java | 49 + src/me/bruce/factions/commands/Vip.java | 65 + src/me/bruce/factions/commands/WB.java | 39 + .../factions/commands/ZorexDeveloper.java | 17 + .../bruce/factions/commands/ZorexRevive.java | 63 + src/me/bruce/factions/commands/nv.java | 39 + src/me/bruce/factions/commands/randomtp.java | 40 + .../factions/conquest/ConquestExecutor.java | 12 + .../conquest/ConquestSetpointsArgument.java | 66 + src/me/bruce/factions/deathban/Deathban.java | 78 + .../factions/deathban/DeathbanListener.java | 182 + .../factions/deathban/DeathbanManager.java | 102 + .../deathban/FlatFileDeathbanManager.java | 145 + .../factions/deathban/StaffReviveCommand.java | 84 + .../deathban/lives/LivesExecutor.java | 23 + .../lives/args/LivesCheckArgument.java | 63 + .../args/LivesCheckDeathbanArgument.java | 101 + .../args/LivesClearDeathbansArgument.java | 40 + .../lives/args/LivesGiveArgument.java | 82 + .../lives/args/LivesReviveArgument.java | 140 + .../deathban/lives/args/LivesSetArgument.java | 68 + .../args/LivesSetDeathbanTimeArgument.java | 57 + .../factions/economy/EconomyCommand.java | 145 + .../factions/economy/EconomyManager.java | 72 + .../economy/FlatFileEconomyManager.java | 87 + src/me/bruce/factions/economy/PayCommand.java | 100 + .../factions/economy/ShopSignListener.java | 114 + .../factions/endoftheworld/EotwCommand.java | 74 + .../factions/endoftheworld/EotwHandler.java | 219 + .../factions/endoftheworld/EotwListener.java | 71 + .../factions/eventutils/CaptureZone.java | 258 + .../factions/eventutils/EventExecutor.java | 24 + .../factions/eventutils/EventScheduler.java | 102 + .../bruce/factions/eventutils/EventTimer.java | 298 + .../bruce/factions/eventutils/EventType.java | 47 + .../argument/EventCancelArgument.java | 45 + .../argument/EventCreateArgument.java | 82 + .../argument/EventDeleteArgument.java | 66 + .../argument/EventRenameArgument.java | 73 + .../argument/EventSetAreaArgument.java | 99 + .../argument/EventSetCapzoneArgument.java | 176 + .../argument/EventStartArgument.java | 65 + .../argument/EventUptimeArgument.java | 53 + .../eventutils/tracker/ConquestTracker.java | 250 + .../eventutils/tracker/EventTracker.java | 37 + .../eventutils/tracker/KothTracker.java | 96 + src/me/bruce/factions/faction/.DS_Store | Bin 0 -> 6148 bytes .../factions/faction/FactionExecutor.java | 85 + .../factions/faction/FactionManager.java | 202 + .../bruce/factions/faction/FactionMember.java | 122 + .../faction/FactionSetDTRArgument.java | 100 + .../bruce/factions/faction/FactionUser.java | 173 + .../faction/FlatFileFactionManager.java | 350 + src/me/bruce/factions/faction/LandMap.java | 146 + .../faction/args/FactionAcceptArgument.java | 105 + .../faction/args/FactionAllyArgument.java | 172 + .../args/FactionAnnouncementArgument.java | 104 + .../faction/args/FactionChatArgument.java | 93 + .../faction/args/FactionClaimArgument.java | 76 + .../args/FactionClaimChunkArgument.java | 64 + .../faction/args/FactionClaimsArgument.java | 118 + .../faction/args/FactionCreateArgument.java | 86 + .../faction/args/FactionDemoteArgument.java | 104 + .../faction/args/FactionDepositArgument.java | 98 + .../faction/args/FactionDisbandArgument.java | 55 + .../faction/args/FactionGuiArugment.java | 36 + .../faction/args/FactionHelpArgument.java | 134 + .../faction/args/FactionHomeArgument.java | 134 + .../faction/args/FactionInviteArgument.java | 135 + .../faction/args/FactionInvitesArgument.java | 69 + .../faction/args/FactionKickArgument.java | 137 + .../faction/args/FactionLeaderArgument.java | 110 + .../faction/args/FactionLeaveArgument.java | 62 + .../faction/args/FactionListArgument.java | 149 + .../faction/args/FactionMapArgument.java | 85 + .../faction/args/FactionOpenArgument.java | 57 + .../faction/args/FactionPromoteArgument.java | 107 + .../faction/args/FactionRenameArgument.java | 104 + .../faction/args/FactionSetHomeArgument.java | 74 + .../faction/args/FactionSettingsArgument.java | 41 + .../faction/args/FactionShowArgument.java | 90 + .../faction/args/FactionStuckArgument.java | 59 + .../args/FactionSubclaimArgumentExecutor.java | 99 + .../faction/args/FactionUnallyArgument.java | 143 + .../faction/args/FactionUnclaimArgument.java | 100 + .../faction/args/FactionUninviteArgument.java | 100 + .../args/FactionUnsubclaimArgument.java | 104 + .../faction/args/FactionWithdrawArgument.java | 105 + .../args/staff/FactionClaimForArgument.java | 90 + .../staff/FactionClearClaimsArgument.java | 149 + .../staff/FactionForceDemoteArgument.java | 68 + .../args/staff/FactionForceJoinArgument.java | 100 + .../args/staff/FactionForceKickArgument.java | 70 + .../staff/FactionForceLeaderArgument.java | 80 + .../staff/FactionForcePromoteArgument.java | 68 + .../args/staff/FactionRemoveArgument.java | 137 + .../FactionSubclaimAddMemberArgument.java | 133 + .../FactionSubclaimCreateArgument.java | 114 + .../FactionSubclaimDelMemberArgument.java | 145 + .../FactionSubclaimDeleteArgument.java | 94 + .../subclaim/FactionSubclaimListArgument.java | 68 + .../FactionSubclaimMembersArgument.java | 107 + .../FactionSubclaimRenameArgument.java | 100 + .../FactionSubclaimStartArgument.java | 63 + .../bruce/factions/faction/claim/Claim.java | 155 + .../factions/faction/claim/ClaimHandler.java | 422 + .../faction/claim/ClaimSelection.java | 201 + .../faction/claim/ClaimWandListener.java | 268 + .../factions/faction/claim/Subclaim.java | 91 + .../faction/claim/SubclaimWandListener.java | 244 + .../faction/event/CaptureZoneEnterEvent.java | 74 + .../faction/event/CaptureZoneLeaveEvent.java | 74 + .../faction/event/FactionChatEvent.java | 83 + .../event/FactionClaimChangeEvent.java | 97 + .../event/FactionClaimChangedEvent.java | 66 + .../faction/event/FactionCreateEvent.java | 51 + .../faction/event/FactionDtrChangeEvent.java | 72 + .../factions/faction/event/FactionEvent.java | 33 + .../event/FactionRelationCreateEvent.java | 69 + .../event/FactionRelationRemoveEvent.java | 70 + .../faction/event/FactionRemoveEvent.java | 51 + .../faction/event/FactionRenameEvent.java | 85 + .../faction/event/PlayerClaimEnterEvent.java | 94 + .../faction/event/PlayerFreezeEvent.java | 40 + .../faction/event/PlayerJoinFactionEvent.java | 82 + .../event/PlayerJoinedFactionEvent.java | 84 + .../event/PlayerLeaveFactionEvent.java | 108 + .../faction/event/PlayerLeftFactionEvent.java | 88 + .../faction/event/cause/ClaimChangeCause.java | 6 + .../event/cause/FactionLeaveCause.java | 6 + .../factions/faction/struct/ChatChannel.java | 143 + .../factions/faction/struct/Raidable.java | 67 + .../factions/faction/struct/RegenStatus.java | 29 + .../factions/faction/struct/Relation.java | 72 + .../bruce/factions/faction/struct/Role.java | 38 + .../faction/type/CapturableFaction.java | 14 + .../faction/type/ClaimableFaction.java | 187 + .../faction/type/ConquestFaction.java | 174 + .../faction/type/EndPortalFaction.java | 54 + .../factions/faction/type/EventFaction.java | 81 + .../bruce/factions/faction/type/Faction.java | 282 + .../type/GlowstoneMountainFaction.java | 54 + .../factions/faction/type/KothFaction.java | 106 + .../factions/faction/type/PlayerFaction.java | 720 ++ .../factions/faction/type/RoadFaction.java | 138 + .../factions/faction/type/SpawnFaction.java | 26 + .../factions/faction/type/WarzoneFaction.java | 26 + .../faction/type/WildernessFaction.java | 25 + .../factions/keysale/keysaleCommand.java | 117 + .../bruce/factions/keysale/keysaletimer.java | 64 + src/me/bruce/factions/koth/KothExecutor.java | 38 + .../factions/koth/args/KothHelpArgument.java | 46 + .../factions/koth/args/KothNextArgument.java | 73 + .../koth/args/KothScheduleArgument.java | 90 + .../koth/args/KothSetCapDelayArgument.java | 96 + src/me/bruce/factions/listener/.DS_Store | Bin 0 -> 6148 bytes .../listener/AutoSmeltOreListener.java | 51 + .../listener/BookDeenchantListener.java | 51 + .../factions/listener/BorderListener.java | 99 + .../factions/listener/BottledExpListener.java | 140 + .../bruce/factions/listener/ChatListener.java | 121 + .../bruce/factions/listener/ColorUtils.java | 9 + src/me/bruce/factions/listener/Cooldowns.java | 56 + .../bruce/factions/listener/CoreListener.java | 222 + .../listener/CreativeClickListener.java | 47 + .../listener/CreeperFriendlyListener.java | 16 + src/me/bruce/factions/listener/Crowbar.java | 180 + .../factions/listener/CrowbarListener.java | 205 + .../factions/listener/DateTimeFormats.java | 47 + .../factions/listener/DeathListener.java | 99 + .../listener/DeathMessageListener.java | 73 + .../factions/listener/DeathSignListener.java | 170 + .../listener/DelayedMessageRunnable.java | 25 + .../factions/listener/ElevatorListener.java | 130 + .../bruce/factions/listener/EndListener.java | 25 + .../listener/EntityLimitListener.java | 37 + .../factions/listener/EventSignListener.java | 99 + .../listener/ExpMultiplierListener.java | 92 + .../factions/listener/FactionListener.java | 266 + .../listener/FastEverythingListener.java | 92 + .../listener/FoundDiamondsListener.java | 92 + .../factions/listener/GlowstoneListener.java | 44 + .../listener/ItemRemoverListener.java | 44 + .../factions/listener/MapkitHandler.java | 5 + .../bruce/factions/listener/MineListener.java | 160 + .../factions/listener/MobFixesListener.java | 23 + .../factions/listener/PlayTimeManager.java | 80 + .../factions/listener/PortalListener.java | 142 + .../bruce/factions/listener/PotListener.java | 48 + .../factions/listener/ProtectionListener.java | 709 ++ .../listener/SignSubclaimListener.java | 354 + .../factions/listener/StaffModeListener.java | 272 + .../factions/listener/StrengthListener.java | 33 + src/me/bruce/factions/listener/Tuple.java | 19 + .../bruce/factions/listener/UUIDFetcher.java | 124 + .../listener/UnRepairableListener.java | 40 + .../bruce/factions/listener/UserManager.java | 103 + .../factions/listener/VanishListener.java | 118 + .../factions/listener/WorldListener.java | 126 + .../combatloggers/CombatLogEntry.java | 13 + .../combatloggers/CombatLogListener.java | 104 + .../CustomEntityRegistration.java | 46 + .../combatloggers/LoggerDeathEvent.java | 30 + .../listener/combatloggers/LoggerEntity.java | 15 + .../combatloggers/LoggerEntityHuman.java | 166 + .../combatloggers/LoggerRemovedEvent.java | 30 + .../combatloggers/LoggerSpawnEvent.java | 38 + .../listener/fixes/ArmorFixListener.java | 30 + .../listener/fixes/BlockHitFixListener.java | 89 + .../fixes/BlockJumpGlitchFixListener.java | 37 + .../listener/fixes/BoatGlitchFixListener.java | 21 + .../fixes/ColonCommandFixListener.java | 16 + .../listener/fixes/CreativeClickListener.java | 47 + .../listener/fixes/CreatureSpawn.java | 17 + .../listener/fixes/EnchantLimitListener.java | 181 + .../fixes/EnderChestRemovalListener.java | 51 + .../fixes/EnderpearlRefundListener.java | 26 + .../listener/fixes/HungerFixListener.java | 43 + .../fixes/InfinityArrowFixListener.java | 23 + .../listener/fixes/PearlGlitchListener.java | 75 + .../listener/fixes/PearlLandListener.java | 48 + .../listener/fixes/PhaseFixListener.java | 53 + .../listener/fixes/PluginViewListener.java | 22 + .../listener/fixes/PortalTrapFixListener.java | 35 + .../listener/fixes/PotionLimitListener.java | 94 + .../fixes/ServerSecurityListener.java | 20 + .../listener/fixes/VoidGlitchFixListener.java | 42 + .../listener/fixes/WeatherFixListener.java | 14 + .../factions/listener/render/BlockFiller.java | 33 + .../listener/render/ProtocolLibHook.java | 95 + .../factions/listener/render/VisualBlock.java | 29 + .../listener/render/VisualBlockData.java | 41 + .../factions/listener/render/VisualType.java | 125 + .../listener/render/VisualiseHandler.java | 308 + .../listener/render/WallBorderListener.java | 253 + src/me/bruce/factions/login/Commands.java | 5 + .../bruce/factions/login/LoginListener1.java | 47 + src/me/bruce/factions/prefix/PrefixInv.java | 47 + src/me/bruce/factions/prefix/PrefixMenu.java | 120 + .../factions/prefix/builder/ItemBuilder1.java | 49 + .../inventory/PrefixInventoryClick.java | 411 + .../prefix/inventory/inv_prefixes.java | 60 + src/me/bruce/factions/prefix/prefix.java | 30 + .../factions/prefix/simplechat/Chat.java | 52 + src/me/bruce/factions/rank/RankCommand.java | 53 + src/me/bruce/factions/rank/RankExecutor.java | 17 + .../factions/rank/args/RankSetArgument.java | 58 + .../bruce/factions/reboot/rebootCommand.java | 118 + src/me/bruce/factions/reboot/reboottimer.java | 63 + src/me/bruce/factions/scoreboard/.DS_Store | Bin 0 -> 6148 bytes .../scoreboard/BufferedObjective.java | 142 + .../factions/scoreboard/PlayerBoard.java | 194 + .../scoreboard/ScoreboardHandler.java | 135 + .../factions/scoreboard/SidebarEntry.java | 52 + .../factions/scoreboard/SidebarProvider.java | 24 + .../scoreboard/helper/ScoreboardHelper.java | Bin 0 -> 29112 bytes .../factions/staff/PlayerVanishEvent.java | 50 + .../bruce/factions/staff/StaffInventory.java | 84 + src/me/bruce/factions/staff/StaffItems.java | 55 + .../factions/staff/StaffModeCommand.java | 128 + .../bruce/factions/staff/StaffPriority.java | 56 + .../bruce/factions/staff/VanishCommand.java | 73 + .../factions/startoftheworld/SotwCommand.java | 118 + .../startoftheworld/SotwListener.java | 54 + .../factions/startoftheworld/SotwTimer.java | 67 + src/me/bruce/factions/timer/GlobalTimer.java | 72 + src/me/bruce/factions/timer/PlayerTimer.java | 195 + src/me/bruce/factions/timer/Timer.java | 69 + .../bruce/factions/timer/TimerCooldown.java | 118 + .../bruce/factions/timer/TimerExecutor.java | 19 + src/me/bruce/factions/timer/TimerManager.java | 143 + .../timer/args/TimerCheckArgument.java | 78 + .../factions/timer/args/TimerSetArgument.java | 127 + .../factions/timer/event/TimerClearEvent.java | 61 + .../timer/event/TimerExpireEvent.java | 61 + .../timer/event/TimerExtendEvent.java | 101 + .../factions/timer/event/TimerPauseEvent.java | 83 + .../factions/timer/event/TimerStartEvent.java | 77 + .../factions/timer/type/ArcherTimer.java | 79 + .../bruce/factions/timer/type/ClassLoad.java | 130 + .../factions/timer/type/CombatTimer.java | 178 + .../factions/timer/type/EnderPearlTimer.java | 300 + .../factions/timer/type/GappleTimer.java | 80 + .../timer/type/InvincibilityTimer.java | 355 + .../factions/timer/type/LogoutTimer.java | 103 + .../bruce/factions/timer/type/StuckTimer.java | 153 + .../factions/timer/type/TeleportTimer.java | 185 + src/me/bruce/factions/ymls/AThing.java | 77 + src/me/bruce/factions/ymls/LangYML.java | 329 + src/me/bruce/factions/ymls/SettingsYML.java | 277 + src/me/bruceboy/framework/EnableMessage.java | 13 + src/me/bruceboy/framework/commands/Fly.java | 38 + .../bruceboy/framework/commands/Gamemode.java | 47 + .../framework/commands/ListCommand.java | 32 + .../bruceboy/framework/commands/Teleport.java | 33 + .../bruceboy/framework/commands/tphere.java | 33 + src/me/bruceboy/tablist/lorexmc/TabList.java | 107 + src/me/bruceboy/tablist/lorexmc/TabTask.java | 108 + .../bruceboy/tablist/lorexmc/utils/Tab.java | 229 + .../tablist/lorexmc/utils/TabAdapter.java | 9 + .../tablist/lorexmc/utils/TabTemplate.java | 108 + .../lorexmc/utils/main/TabCreator.java | 125 + src/me/tablist/api/tabapi/Tab.java | 57 + src/me/tablist/api/tablist/Protocol.java | 60 + src/me/tablist/api/tablist/Reflex.java | 23 + src/me/tablist/api/tablist/Xernos.java | 232 + .../api/tablist/adapter/TablistAdapter.java | 183 + .../tablist/api/tinyprotocol/Reflection.java | 403 + .../api/tinyprotocol/TinyProtocol.java | 524 ++ .../commons/collections4/ArrayStack.java | 173 + src/org/apache/commons/collections4/Bag.java | 235 + .../apache/commons/collections4/BagUtils.java | 295 + .../apache/commons/collections4/BidiMap.java | 160 + .../collections4/BoundedCollection.java | 50 + .../commons/collections4/BoundedMap.java | 45 + .../apache/commons/collections4/Closure.java | 49 + .../commons/collections4/ClosureUtils.java | 438 + .../commons/collections4/CollectionUtils.java | 2200 +++++ .../commons/collections4/ComparatorUtils.java | 261 + .../collections4/EnumerationUtils.java | 111 + .../apache/commons/collections4/Equator.java | 50 + .../apache/commons/collections4/Factory.java | 46 + .../commons/collections4/FactoryUtils.java | 169 + .../commons/collections4/FluentIterable.java | 554 ++ .../collections4/FunctorException.java | 73 + src/org/apache/commons/collections4/Get.java | 77 + .../commons/collections4/IterableGet.java | 48 + .../commons/collections4/IterableMap.java | 47 + .../collections4/IterableSortedMap.java | 33 + .../commons/collections4/IterableUtils.java | 1235 +++ .../commons/collections4/IteratorUtils.java | 1774 ++++ .../apache/commons/collections4/KeyValue.java | 49 + .../commons/collections4/ListUtils.java | 790 ++ .../commons/collections4/ListValuedMap.java | 73 + .../commons/collections4/MapIterator.java | 126 + .../apache/commons/collections4/MapUtils.java | 2081 +++++ .../apache/commons/collections4/MultiMap.java | 191 + .../commons/collections4/MultiMapUtils.java | 297 + .../apache/commons/collections4/MultiSet.java | 291 + .../commons/collections4/MultiSetUtils.java | 129 + .../commons/collections4/MultiValuedMap.java | 356 + .../commons/collections4/OrderedBidiMap.java | 54 + .../commons/collections4/OrderedIterator.java | 51 + .../commons/collections4/OrderedMap.java | 80 + .../collections4/OrderedMapIterator.java | 51 + .../commons/collections4/Predicate.java | 54 + .../commons/collections4/PredicateUtils.java | 628 ++ src/org/apache/commons/collections4/Put.java | 55 + .../commons/collections4/QueueUtils.java | 121 + .../collections4/ResettableIterator.java | 38 + .../collections4/ResettableListIterator.java | 33 + .../apache/commons/collections4/SetUtils.java | 718 ++ .../commons/collections4/SetValuedMap.java | 72 + .../commons/collections4/SortedBag.java | 54 + .../commons/collections4/SortedBidiMap.java | 62 + .../commons/collections4/SplitMapUtils.java | 281 + .../commons/collections4/Transformer.java | 56 + .../collections4/TransformerUtils.java | 575 ++ src/org/apache/commons/collections4/Trie.java | 48 + .../commons/collections4/TrieUtils.java | 54 + .../commons/collections4/Unmodifiable.java | 40 + .../bag/AbstractBagDecorator.java | 100 + .../collections4/bag/AbstractMapBag.java | 659 ++ .../bag/AbstractSortedBagDecorator.java | 85 + .../collections4/bag/CollectionBag.java | 257 + .../collections4/bag/CollectionSortedBag.java | 177 + .../commons/collections4/bag/HashBag.java | 79 + .../collections4/bag/PredicatedBag.java | 135 + .../collections4/bag/PredicatedSortedBag.java | 119 + .../collections4/bag/SynchronizedBag.java | 162 + .../bag/SynchronizedSortedBag.java | 116 + .../collections4/bag/TransformedBag.java | 159 + .../bag/TransformedSortedBag.java | 143 + .../commons/collections4/bag/TreeBag.java | 146 + .../collections4/bag/UnmodifiableBag.java | 165 + .../bag/UnmodifiableSortedBag.java | 162 + .../collections4/bag/package-info.java | 41 + .../bidimap/AbstractBidiMapDecorator.java | 90 + .../bidimap/AbstractDualBidiMap.java | 829 ++ .../AbstractOrderedBidiMapDecorator.java | 94 + .../AbstractSortedBidiMapDecorator.java | 96 + .../collections4/bidimap/DualHashBidiMap.java | 114 + .../bidimap/DualLinkedHashBidiMap.java | 111 + .../collections4/bidimap/DualTreeBidiMap.java | 428 + .../collections4/bidimap/TreeBidiMap.java | 2335 ++++++ .../bidimap/UnmodifiableBidiMap.java | 141 + .../bidimap/UnmodifiableOrderedBidiMap.java | 154 + .../bidimap/UnmodifiableSortedBidiMap.java | 166 + .../collections4/bidimap/package-info.java | 42 + .../AbstractCollectionDecorator.java | 185 + .../collection/CompositeCollection.java | 538 ++ .../collection/IndexedCollection.java | 279 + .../collection/PredicatedCollection.java | 501 ++ .../collection/SynchronizedCollection.java | 243 + .../collection/TransformedCollection.java | 169 + .../UnmodifiableBoundedCollection.java | 175 + .../collection/UnmodifiableCollection.java | 115 + .../collections4/collection/package-info.java | 38 + .../comparators/BooleanComparator.java | 194 + .../comparators/ComparableComparator.java | 138 + .../comparators/ComparatorChain.java | 361 + .../comparators/FixedOrderComparator.java | 313 + .../comparators/NullComparator.java | 191 + .../comparators/ReverseComparator.java | 125 + .../comparators/TransformingComparator.java | 134 + .../comparators/package-info.java | 28 + .../functors/AbstractQuantifierPredicate.java | 59 + .../collections4/functors/AllPredicate.java | 125 + .../collections4/functors/AndPredicate.java | 100 + .../collections4/functors/AnyPredicate.java | 122 + .../functors/CatchAndRethrowClosure.java | 80 + .../collections4/functors/ChainedClosure.java | 139 + .../functors/ChainedTransformer.java | 141 + .../functors/CloneTransformer.java | 77 + .../functors/ClosureTransformer.java | 92 + .../functors/ComparatorPredicate.java | 214 + .../functors/ConstantFactory.java | 94 + .../functors/ConstantTransformer.java | 138 + .../collections4/functors/DefaultEquator.java | 87 + .../collections4/functors/EqualPredicate.java | 132 + .../functors/ExceptionClosure.java | 76 + .../functors/ExceptionFactory.java | 75 + .../functors/ExceptionPredicate.java | 77 + .../functors/ExceptionTransformer.java | 79 + .../functors/FactoryTransformer.java | 93 + .../collections4/functors/FalsePredicate.java | 74 + .../collections4/functors/ForClosure.java | 113 + .../collections4/functors/FunctorUtils.java | 222 + .../functors/IdentityPredicate.java | 89 + .../collections4/functors/IfClosure.java | 171 + .../collections4/functors/IfTransformer.java | 171 + .../functors/InstanceofPredicate.java | 89 + .../functors/InstantiateFactory.java | 149 + .../functors/InstantiateTransformer.java | 139 + .../functors/InvokerTransformer.java | 165 + .../collections4/functors/MapTransformer.java | 93 + .../collections4/functors/NOPClosure.java | 73 + .../collections4/functors/NOPTransformer.java | 74 + .../collections4/functors/NonePredicate.java | 113 + .../functors/NotNullPredicate.java | 74 + .../collections4/functors/NotPredicate.java | 92 + .../functors/NullIsExceptionPredicate.java | 98 + .../functors/NullIsFalsePredicate.java | 95 + .../functors/NullIsTruePredicate.java | 95 + .../collections4/functors/NullPredicate.java | 74 + .../collections4/functors/OnePredicate.java | 118 + .../collections4/functors/OrPredicate.java | 100 + .../functors/PredicateDecorator.java | 41 + .../functors/PredicateTransformer.java | 91 + .../functors/PrototypeFactory.java | 213 + .../functors/StringValueTransformer.java | 74 + .../collections4/functors/SwitchClosure.java | 205 + .../functors/SwitchTransformer.java | 222 + .../functors/TransformedPredicate.java | 116 + .../functors/TransformerClosure.java | 90 + .../functors/TransformerPredicate.java | 97 + .../collections4/functors/TruePredicate.java | 74 + .../functors/UniquePredicate.java | 74 + .../collections4/functors/WhileClosure.java | 134 + .../collections4/functors/package-info.java | 43 + .../iterators/AbstractEmptyIterator.java | 76 + .../iterators/AbstractEmptyMapIterator.java | 46 + .../iterators/AbstractIteratorDecorator.java | 51 + .../AbstractListIteratorDecorator.java | 118 + .../AbstractMapIteratorDecorator.java | 100 + .../AbstractOrderedMapIteratorDecorator.java | 112 + .../AbstractUntypedIteratorDecorator.java | 71 + .../collections4/iterators/ArrayIterator.java | 219 + .../iterators/ArrayListIterator.java | 232 + .../iterators/BoundedIterator.java | 145 + .../iterators/CollatingIterator.java | 423 + .../collections4/iterators/EmptyIterator.java | 82 + .../iterators/EmptyListIterator.java | 82 + .../iterators/EmptyMapIterator.java | 60 + .../iterators/EmptyOrderedIterator.java | 58 + .../iterators/EmptyOrderedMapIterator.java | 60 + .../iterators/EntrySetMapIterator.java | 188 + .../iterators/EnumerationIterator.java | 149 + .../iterators/FilterIterator.java | 193 + .../iterators/FilterListIterator.java | 288 + .../collections4/iterators/IteratorChain.java | 294 + .../iterators/IteratorEnumeration.java | 99 + .../iterators/IteratorIterable.java | 140 + .../iterators/LazyIteratorChain.java | 162 + .../iterators/ListIteratorWrapper.java | 282 + .../iterators/LoopingIterator.java | 132 + .../iterators/LoopingListIterator.java | 265 + .../iterators/NodeListIterator.java | 97 + .../iterators/ObjectArrayIterator.java | 191 + .../iterators/ObjectArrayListIterator.java | 220 + .../iterators/ObjectGraphIterator.java | 267 + .../iterators/PeekingIterator.java | 170 + .../iterators/PermutationIterator.java | 166 + .../iterators/PushbackIterator.java | 119 + .../iterators/ReverseListIterator.java | 194 + .../iterators/SingletonIterator.java | 130 + .../iterators/SingletonListIterator.java | 189 + .../iterators/SkippingIterator.java | 100 + .../iterators/TransformIterator.java | 154 + .../iterators/UniqueFilterIterator.java | 45 + .../iterators/UnmodifiableIterator.java | 90 + .../iterators/UnmodifiableListIterator.java | 118 + .../iterators/UnmodifiableMapIterator.java | 105 + .../UnmodifiableOrderedMapIterator.java | 117 + .../iterators/ZippingIterator.java | 171 + .../collections4/iterators/package-info.java | 28 + .../keyvalue/AbstractKeyValue.java | 91 + .../keyvalue/AbstractMapEntry.java | 94 + .../keyvalue/AbstractMapEntryDecorator.java | 95 + .../keyvalue/DefaultKeyValue.java | 164 + .../keyvalue/DefaultMapEntry.java | 69 + .../collections4/keyvalue/MultiKey.java | 305 + .../collections4/keyvalue/TiedMapEntry.java | 144 + .../keyvalue/UnmodifiableMapEntry.java | 83 + .../collections4/keyvalue/package-info.java | 31 + .../collections4/list/AbstractLinkedList.java | 1132 +++ .../list/AbstractListDecorator.java | 133 + .../AbstractSerializableListDecorator.java | 76 + .../list/CursorableLinkedList.java | 649 ++ .../collections4/list/FixedSizeList.java | 189 + .../commons/collections4/list/GrowthList.java | 207 + .../commons/collections4/list/LazyList.java | 148 + .../list/NodeCachingLinkedList.java | 250 + .../collections4/list/PredicatedList.java | 205 + .../collections4/list/SetUniqueList.java | 437 + .../collections4/list/TransformedList.java | 223 + .../commons/collections4/list/TreeList.java | 1163 +++ .../collections4/list/UnmodifiableList.java | 151 + .../collections4/list/package-info.java | 46 + .../collections4/map/AbstractHashedMap.java | 1468 ++++ .../map/AbstractInputCheckedMapDecorator.java | 214 + .../collections4/map/AbstractIterableMap.java | 37 + .../collections4/map/AbstractLinkedMap.java | 653 ++ .../map/AbstractMapDecorator.java | 160 + .../map/AbstractOrderedMapDecorator.java | 97 + .../map/AbstractReferenceMap.java | 1106 +++ .../map/AbstractSortedMapDecorator.java | 183 + .../collections4/map/CaseInsensitiveMap.java | 174 + .../collections4/map/CompositeMap.java | 603 ++ .../collections4/map/DefaultedMap.java | 236 + .../map/EntrySetToMapIteratorAdapter.java | 124 + .../collections4/map/FixedSizeMap.java | 179 + .../collections4/map/FixedSizeSortedMap.java | 190 + .../commons/collections4/map/Flat3Map.java | 1285 +++ .../commons/collections4/map/HashedMap.java | 123 + .../commons/collections4/map/LRUMap.java | 584 ++ .../commons/collections4/map/LazyMap.java | 194 + .../collections4/map/LazySortedMap.java | 182 + .../commons/collections4/map/LinkedMap.java | 319 + .../collections4/map/ListOrderedMap.java | 832 ++ .../commons/collections4/map/MultiKeyMap.java | 1020 +++ .../collections4/map/MultiValueMap.java | 612 ++ .../collections4/map/PassiveExpiringMap.java | 562 ++ .../collections4/map/PredicatedMap.java | 210 + .../collections4/map/PredicatedSortedMap.java | 143 + .../map/ReferenceIdentityMap.java | 263 + .../collections4/map/ReferenceMap.java | 199 + .../collections4/map/SingletonMap.java | 625 ++ .../collections4/map/StaticBucketMap.java | 745 ++ .../collections4/map/TransformedMap.java | 274 + .../map/TransformedSortedMap.java | 184 + .../map/UnmodifiableEntrySet.java | 188 + .../collections4/map/UnmodifiableMap.java | 165 + .../map/UnmodifiableOrderedMap.java | 161 + .../map/UnmodifiableSortedMap.java | 182 + .../collections4/map/package-info.java | 60 + .../multimap/AbstractListValuedMap.java | 294 + .../multimap/AbstractMultiValuedMap.java | 966 +++ .../AbstractMultiValuedMapDecorator.java | 193 + .../multimap/AbstractSetValuedMap.java | 139 + .../multimap/ArrayListValuedHashMap.java | 147 + .../multimap/HashSetValuedHashMap.java | 135 + .../multimap/TransformedMultiValuedMap.java | 218 + .../multimap/UnmodifiableMultiValuedMap.java | 161 + .../collections4/multimap/package-info.java | 38 + .../multiset/AbstractMapMultiSet.java | 591 ++ .../multiset/AbstractMultiSet.java | 519 ++ .../multiset/AbstractMultiSetDecorator.java | 109 + .../collections4/multiset/HashMultiSet.java | 78 + .../multiset/PredicatedMultiSet.java | 144 + .../multiset/SynchronizedMultiSet.java | 175 + .../multiset/UnmodifiableMultiSet.java | 173 + .../collections4/multiset/package-info.java | 40 + .../apache/commons/collections4/overview.html | 113 + .../commons/collections4/package-info.java | 29 + .../queue/AbstractQueueDecorator.java | 100 + .../collections4/queue/CircularFifoQueue.java | 447 + .../collections4/queue/PredicatedQueue.java | 136 + .../collections4/queue/TransformedQueue.java | 150 + .../collections4/queue/UnmodifiableQueue.java | 161 + .../collections4/queue/package-info.java | 37 + .../collections4/sequence/CommandVisitor.java | 146 + .../collections4/sequence/DeleteCommand.java | 58 + .../collections4/sequence/EditCommand.java | 84 + .../collections4/sequence/EditScript.java | 136 + .../collections4/sequence/InsertCommand.java | 59 + .../collections4/sequence/KeepCommand.java | 59 + .../sequence/ReplacementsFinder.java | 116 + .../sequence/ReplacementsHandler.java | 56 + .../sequence/SequencesComparator.java | 355 + .../collections4/sequence/package-info.java | 77 + .../set/AbstractNavigableSetDecorator.java | 125 + .../set/AbstractSerializableSetDecorator.java | 76 + .../set/AbstractSetDecorator.java | 79 + .../set/AbstractSortedSetDecorator.java | 101 + .../collections4/set/CompositeSet.java | 560 ++ .../collections4/set/ListOrderedSet.java | 430 + .../collections4/set/MapBackedSet.java | 192 + .../set/PredicatedNavigableSet.java | 160 + .../collections4/set/PredicatedSet.java | 111 + .../collections4/set/PredicatedSortedSet.java | 136 + .../set/TransformedNavigableSet.java | 185 + .../collections4/set/TransformedSet.java | 124 + .../set/TransformedSortedSet.java | 161 + .../set/UnmodifiableNavigableSet.java | 187 + .../collections4/set/UnmodifiableSet.java | 112 + .../set/UnmodifiableSortedSet.java | 158 + .../collections4/set/package-info.java | 42 + .../AbstractIterableGetMapDecorator.java | 144 + .../splitmap/TransformedSplitMap.java | 236 + .../collections4/splitmap/package-info.java | 38 + .../trie/AbstractBitwiseTrie.java | 218 + .../trie/AbstractPatriciaTrie.java | 2436 ++++++ .../collections4/trie/KeyAnalyzer.java | 166 + .../collections4/trie/PatriciaTrie.java | 71 + .../collections4/trie/UnmodifiableTrie.java | 215 + .../trie/analyzer/StringKeyAnalyzer.java | 134 + .../trie/analyzer/package-info.java | 23 + .../collections4/trie/package-info.java | 37 + timers.yml | 0 1544 files changed, 389411 insertions(+) create mode 100644 .DS_Store create mode 100644 .classpath create mode 100644 .idea/artifacts/Vengeful_jar.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/libraries/PermissionsEx_1_23_4.xml create mode 100644 .idea/libraries/spigot.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 .project create mode 100644 README.md create mode 100644 Vengeful.iml create mode 100644 balances.yml create mode 100644 bin/.DS_Store create mode 100644 bin/.classpath create mode 100644 bin/.gitignore create mode 100644 bin/.idea/artifacts/Vengeful_jar.xml create mode 100644 bin/.idea/encodings.xml create mode 100644 bin/.idea/libraries/PermissionsEx_1_23_4.xml create mode 100644 bin/.idea/libraries/spigot.xml create mode 100644 bin/.idea/misc.xml create mode 100644 bin/.idea/modules.xml create mode 100644 bin/.idea/vcs.xml create mode 100644 bin/.idea/workspace.xml create mode 100644 bin/.project create mode 100644 bin/LICENSE create mode 100644 bin/LorexMC/us/utils/BukkitUtils.class create mode 100644 bin/LorexMC/us/utils/Color.class create mode 100644 bin/LorexMC/us/utils/ConcurrentValueOrderedMap$InternalEntry.class create mode 100644 bin/LorexMC/us/utils/ConcurrentValueOrderedMap.class create mode 100644 bin/LorexMC/us/utils/Config.class create mode 100644 bin/LorexMC/us/utils/DelayedMessageRunnable.class create mode 100644 bin/LorexMC/us/utils/DurationFormatter.class create mode 100644 bin/LorexMC/us/utils/ExperienceManager.class create mode 100644 bin/LorexMC/us/utils/GenericUtils.class create mode 100644 bin/LorexMC/us/utils/InventorySerialisation.class create mode 100644 bin/LorexMC/us/utils/InventoryUtils.class create mode 100644 bin/LorexMC/us/utils/ItemBuilder.class create mode 100644 bin/LorexMC/us/utils/JavaUtils.class create mode 100644 bin/LorexMC/us/utils/MapSorting$1.class create mode 100644 bin/LorexMC/us/utils/MapSorting$2.class create mode 100644 bin/LorexMC/us/utils/MapSorting.class create mode 100644 bin/LorexMC/us/utils/NmsUtils.class create mode 100644 bin/LorexMC/us/utils/ParticleEffect.class create mode 100644 bin/LorexMC/us/utils/PersistableLocation.class create mode 100644 bin/LorexMC/us/utils/SignHandler$1.class create mode 100644 bin/LorexMC/us/utils/SignHandler$SignChange.class create mode 100644 bin/LorexMC/us/utils/SignHandler.class create mode 100644 bin/LorexMC/us/utils/SpigotUtils.class create mode 100644 bin/LorexMC/us/utils/UUIDFetcher.class create mode 100644 bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat$1.class create mode 100644 bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.class create mode 100644 bin/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.class create mode 100644 bin/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.class create mode 100644 bin/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.class create mode 100644 bin/LorexMC/us/utils/internal/com/bruce/base/Callback.class create mode 100644 bin/LorexMC/us/utils/other/chat/ChatUtil.class create mode 100644 bin/LorexMC/us/utils/other/chat/ClickAction.class create mode 100644 bin/LorexMC/us/utils/other/chat/HoverAction.class create mode 100644 bin/LorexMC/us/utils/other/chat/Lang.class create mode 100644 bin/LorexMC/us/utils/other/chat/Text.class create mode 100644 bin/LorexMC/us/utils/other/chat/Trans.class create mode 100644 bin/LorexMC/us/utils/other/command/ArgumentExecutor.class create mode 100644 bin/LorexMC/us/utils/other/command/CommandArgument.class create mode 100644 bin/LorexMC/us/utils/other/command/CommandWrapper$ArgumentComparator.class create mode 100644 bin/LorexMC/us/utils/other/command/CommandWrapper.class create mode 100644 bin/LorexMC/us/utils/other/cuboid/CoordinatePair.class create mode 100644 bin/LorexMC/us/utils/other/cuboid/Cuboid.class create mode 100644 bin/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.class create mode 100644 bin/LorexMC/us/utils/other/cuboid/CuboidDirection.class create mode 100644 bin/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.class create mode 100644 bin/LorexMC/us/utils/other/cuboid/NamedCuboid.class create mode 100644 bin/LorexMC/us/utils/other/imagemessage/ImageChar.class create mode 100644 bin/LorexMC/us/utils/other/imagemessage/ImageMessage.class create mode 100644 bin/LorexMC/us/utils/other/itemdb/ItemData.class create mode 100644 bin/LorexMC/us/utils/other/itemdb/ItemDb.class create mode 100644 bin/LorexMC/us/utils/other/itemdb/ManagedFile.class create mode 100644 bin/LorexMC/us/utils/other/itemdb/SimpleItemDb$1.class create mode 100644 bin/LorexMC/us/utils/other/itemdb/SimpleItemDb.class create mode 100644 bin/README.md create mode 100644 bin/Vengeful.iml create mode 100644 bin/balances.yml create mode 100644 bin/config.yml create mode 100644 bin/coords.txt create mode 100644 bin/enderdragon-art-old.png create mode 100644 bin/enderdragon-art.png create mode 100644 bin/event-schedules.txt create mode 100644 bin/faction-users.yml create mode 100644 bin/factions.yml create mode 100644 bin/gopple-art.png create mode 100644 bin/help.txt create mode 100644 bin/items.csv create mode 100644 bin/lives.yml create mode 100644 bin/locale.yml create mode 100644 bin/plugin.yml create mode 100644 bin/settings.yml create mode 100644 bin/timers.yml create mode 100644 config.yml create mode 100644 coords.txt create mode 100644 enderdragon-art-old.png create mode 100644 enderdragon-art.png create mode 100644 event-schedules.txt create mode 100644 faction-users.yml create mode 100644 factions.yml create mode 100644 gopple-art.png create mode 100644 help.txt create mode 100644 items.csv create mode 100644 lives.yml create mode 100644 locale.yml create mode 100644 plugin.yml create mode 100644 settings.yml create mode 100644 src/LorexMC/us/utils/BukkitUtils.java create mode 100644 src/LorexMC/us/utils/Color.java create mode 100644 src/LorexMC/us/utils/ConcurrentValueOrderedMap.java create mode 100644 src/LorexMC/us/utils/Config.java create mode 100644 src/LorexMC/us/utils/DelayedMessageRunnable.java create mode 100644 src/LorexMC/us/utils/DurationFormatter.java create mode 100644 src/LorexMC/us/utils/ExperienceManager.java create mode 100644 src/LorexMC/us/utils/GenericUtils.java create mode 100644 src/LorexMC/us/utils/InventorySerialisation.java create mode 100644 src/LorexMC/us/utils/InventoryUtils.java create mode 100644 src/LorexMC/us/utils/ItemBuilder.java create mode 100644 src/LorexMC/us/utils/JavaUtils.java create mode 100644 src/LorexMC/us/utils/MapSorting.java create mode 100644 src/LorexMC/us/utils/NmsUtils.java create mode 100644 src/LorexMC/us/utils/ParticleEffect.java create mode 100644 src/LorexMC/us/utils/PersistableLocation.java create mode 100644 src/LorexMC/us/utils/SignHandler.java create mode 100644 src/LorexMC/us/utils/SpigotUtils.java create mode 100644 src/LorexMC/us/utils/UUIDFetcher.java create mode 100644 src/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.java create mode 100644 src/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.java create mode 100644 src/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.java create mode 100644 src/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.java create mode 100644 src/LorexMC/us/utils/internal/com/bruce/base/Callback.java create mode 100644 src/LorexMC/us/utils/other/chat/ChatUtil.java create mode 100644 src/LorexMC/us/utils/other/chat/ClickAction.java create mode 100644 src/LorexMC/us/utils/other/chat/HoverAction.java create mode 100644 src/LorexMC/us/utils/other/chat/Lang.java create mode 100644 src/LorexMC/us/utils/other/chat/Text.java create mode 100644 src/LorexMC/us/utils/other/chat/Trans.java create mode 100644 src/LorexMC/us/utils/other/command/ArgumentExecutor.java create mode 100644 src/LorexMC/us/utils/other/command/CommandArgument.java create mode 100644 src/LorexMC/us/utils/other/command/CommandWrapper.java create mode 100644 src/LorexMC/us/utils/other/cuboid/CoordinatePair.java create mode 100644 src/LorexMC/us/utils/other/cuboid/Cuboid.java create mode 100644 src/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.java create mode 100644 src/LorexMC/us/utils/other/cuboid/CuboidDirection.java create mode 100644 src/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.java create mode 100644 src/LorexMC/us/utils/other/cuboid/NamedCuboid.java create mode 100644 src/LorexMC/us/utils/other/imagemessage/ImageChar.java create mode 100644 src/LorexMC/us/utils/other/imagemessage/ImageMessage.java create mode 100644 src/LorexMC/us/utils/other/itemdb/ItemData.java create mode 100644 src/LorexMC/us/utils/other/itemdb/ItemDb.java create mode 100644 src/LorexMC/us/utils/other/itemdb/ManagedFile.java create mode 100644 src/LorexMC/us/utils/other/itemdb/SimpleItemDb.java create mode 100644 src/gnu/trove/TByteCollection.java create mode 100644 src/gnu/trove/TCharCollection.java create mode 100644 src/gnu/trove/TCollections.java create mode 100644 src/gnu/trove/TDecorators.java create mode 100644 src/gnu/trove/TDoubleCollection.java create mode 100644 src/gnu/trove/TFloatCollection.java create mode 100644 src/gnu/trove/TIntCollection.java create mode 100644 src/gnu/trove/TLongCollection.java create mode 100644 src/gnu/trove/TShortCollection.java create mode 100644 src/gnu/trove/Version.java create mode 100644 src/gnu/trove/decorator/TByteByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TByteCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TByteDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TByteFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TByteIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TByteListDecorator.java create mode 100644 src/gnu/trove/decorator/TByteLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TByteObjectMapDecorator.java create mode 100644 src/gnu/trove/decorator/TByteSetDecorator.java create mode 100644 src/gnu/trove/decorator/TByteShortMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharListDecorator.java create mode 100644 src/gnu/trove/decorator/TCharLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharObjectMapDecorator.java create mode 100644 src/gnu/trove/decorator/TCharSetDecorator.java create mode 100644 src/gnu/trove/decorator/TCharShortMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleListDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleObjectMapDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleSetDecorator.java create mode 100644 src/gnu/trove/decorator/TDoubleShortMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatListDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatObjectMapDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatSetDecorator.java create mode 100644 src/gnu/trove/decorator/TFloatShortMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntListDecorator.java create mode 100644 src/gnu/trove/decorator/TIntLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntObjectMapDecorator.java create mode 100644 src/gnu/trove/decorator/TIntSetDecorator.java create mode 100644 src/gnu/trove/decorator/TIntShortMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongListDecorator.java create mode 100644 src/gnu/trove/decorator/TLongLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongObjectMapDecorator.java create mode 100644 src/gnu/trove/decorator/TLongSetDecorator.java create mode 100644 src/gnu/trove/decorator/TLongShortMapDecorator.java create mode 100644 src/gnu/trove/decorator/TObjectByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TObjectCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TObjectDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TObjectFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TObjectIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TObjectLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TObjectShortMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortByteMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortCharMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortDoubleMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortFloatMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortIntMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortListDecorator.java create mode 100644 src/gnu/trove/decorator/TShortLongMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortObjectMapDecorator.java create mode 100644 src/gnu/trove/decorator/TShortSetDecorator.java create mode 100644 src/gnu/trove/decorator/TShortShortMapDecorator.java create mode 100644 src/gnu/trove/function/TByteFunction.java create mode 100644 src/gnu/trove/function/TCharFunction.java create mode 100644 src/gnu/trove/function/TDoubleFunction.java create mode 100644 src/gnu/trove/function/TFloatFunction.java create mode 100644 src/gnu/trove/function/TIntFunction.java create mode 100644 src/gnu/trove/function/TLongFunction.java create mode 100644 src/gnu/trove/function/TObjectFunction.java create mode 100644 src/gnu/trove/function/TShortFunction.java create mode 100644 src/gnu/trove/impl/Constants.java create mode 100644 src/gnu/trove/impl/HashFunctions.java create mode 100644 src/gnu/trove/impl/PrimeFinder.java create mode 100644 src/gnu/trove/impl/hash/TByteByteHash.java create mode 100644 src/gnu/trove/impl/hash/TByteCharHash.java create mode 100644 src/gnu/trove/impl/hash/TByteDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TByteFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TByteHash.java create mode 100644 src/gnu/trove/impl/hash/TByteIntHash.java create mode 100644 src/gnu/trove/impl/hash/TByteLongHash.java create mode 100644 src/gnu/trove/impl/hash/TByteShortHash.java create mode 100644 src/gnu/trove/impl/hash/TCharByteHash.java create mode 100644 src/gnu/trove/impl/hash/TCharCharHash.java create mode 100644 src/gnu/trove/impl/hash/TCharDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TCharFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TCharHash.java create mode 100644 src/gnu/trove/impl/hash/TCharIntHash.java create mode 100644 src/gnu/trove/impl/hash/TCharLongHash.java create mode 100644 src/gnu/trove/impl/hash/TCharShortHash.java create mode 100644 src/gnu/trove/impl/hash/TCustomObjectHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleByteHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleCharHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleIntHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleLongHash.java create mode 100644 src/gnu/trove/impl/hash/TDoubleShortHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatByteHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatCharHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatIntHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatLongHash.java create mode 100644 src/gnu/trove/impl/hash/TFloatShortHash.java create mode 100644 src/gnu/trove/impl/hash/THash.java create mode 100644 src/gnu/trove/impl/hash/THashIterator.java create mode 100644 src/gnu/trove/impl/hash/THashPrimitiveIterator.java create mode 100644 src/gnu/trove/impl/hash/TIntByteHash.java create mode 100644 src/gnu/trove/impl/hash/TIntCharHash.java create mode 100644 src/gnu/trove/impl/hash/TIntDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TIntFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TIntHash.java create mode 100644 src/gnu/trove/impl/hash/TIntIntHash.java create mode 100644 src/gnu/trove/impl/hash/TIntLongHash.java create mode 100644 src/gnu/trove/impl/hash/TIntShortHash.java create mode 100644 src/gnu/trove/impl/hash/TLongByteHash.java create mode 100644 src/gnu/trove/impl/hash/TLongCharHash.java create mode 100644 src/gnu/trove/impl/hash/TLongDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TLongFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TLongHash.java create mode 100644 src/gnu/trove/impl/hash/TLongIntHash.java create mode 100644 src/gnu/trove/impl/hash/TLongLongHash.java create mode 100644 src/gnu/trove/impl/hash/TLongShortHash.java create mode 100644 src/gnu/trove/impl/hash/TObjectHash.java create mode 100644 src/gnu/trove/impl/hash/TPrimitiveHash.java create mode 100644 src/gnu/trove/impl/hash/TShortByteHash.java create mode 100644 src/gnu/trove/impl/hash/TShortCharHash.java create mode 100644 src/gnu/trove/impl/hash/TShortDoubleHash.java create mode 100644 src/gnu/trove/impl/hash/TShortFloatHash.java create mode 100644 src/gnu/trove/impl/hash/TShortHash.java create mode 100644 src/gnu/trove/impl/hash/TShortIntHash.java create mode 100644 src/gnu/trove/impl/hash/TShortLongHash.java create mode 100644 src/gnu/trove/impl/hash/TShortShortHash.java create mode 100644 src/gnu/trove/impl/package.html create mode 100644 src/gnu/trove/impl/sync/SynchronizedCollection.java create mode 100644 src/gnu/trove/impl/sync/SynchronizedSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteCollection.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteObjectMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedByteShortMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharCollection.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharObjectMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedCharShortMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleCollection.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleObjectMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedDoubleShortMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatCollection.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatObjectMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedFloatShortMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntCollection.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntObjectMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedIntShortMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongCollection.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongObjectMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedLongShortMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedObjectByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedObjectCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedObjectDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedObjectFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedObjectIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedObjectLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedObjectShortMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedRandomAccessByteList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedRandomAccessCharList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedRandomAccessDoubleList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedRandomAccessFloatList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedRandomAccessIntList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedRandomAccessLongList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedRandomAccessShortList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortByteMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortCharMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortCollection.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortDoubleMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortFloatMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortIntMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortList.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortLongMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortObjectMap.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortSet.java create mode 100644 src/gnu/trove/impl/sync/TSynchronizedShortShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCollection.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteObjectMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteSet.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableByteShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCollection.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharObjectMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharSet.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableCharShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCollection.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleObjectMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleSet.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCollection.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatObjectMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatSet.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCollection.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntObjectMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntSet.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableIntShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCollection.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongObjectMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongSet.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableLongShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectShortMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessByteList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessCharList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessDoubleList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessFloatList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessIntList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessLongList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessShortList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortByteMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCharMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCollection.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortDoubleMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortFloatMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortIntMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortList.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortLongMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortObjectMap.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortSet.java create mode 100644 src/gnu/trove/impl/unmodifiable/TUnmodifiableShortShortMap.java create mode 100644 src/gnu/trove/iterator/TAdvancingIterator.java create mode 100644 src/gnu/trove/iterator/TByteByteIterator.java create mode 100644 src/gnu/trove/iterator/TByteCharIterator.java create mode 100644 src/gnu/trove/iterator/TByteDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TByteFloatIterator.java create mode 100644 src/gnu/trove/iterator/TByteIntIterator.java create mode 100644 src/gnu/trove/iterator/TByteIterator.java create mode 100644 src/gnu/trove/iterator/TByteLongIterator.java create mode 100644 src/gnu/trove/iterator/TByteObjectIterator.java create mode 100644 src/gnu/trove/iterator/TByteShortIterator.java create mode 100644 src/gnu/trove/iterator/TCharByteIterator.java create mode 100644 src/gnu/trove/iterator/TCharCharIterator.java create mode 100644 src/gnu/trove/iterator/TCharDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TCharFloatIterator.java create mode 100644 src/gnu/trove/iterator/TCharIntIterator.java create mode 100644 src/gnu/trove/iterator/TCharIterator.java create mode 100644 src/gnu/trove/iterator/TCharLongIterator.java create mode 100644 src/gnu/trove/iterator/TCharObjectIterator.java create mode 100644 src/gnu/trove/iterator/TCharShortIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleByteIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleCharIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleFloatIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleIntIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleLongIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleObjectIterator.java create mode 100644 src/gnu/trove/iterator/TDoubleShortIterator.java create mode 100644 src/gnu/trove/iterator/TFloatByteIterator.java create mode 100644 src/gnu/trove/iterator/TFloatCharIterator.java create mode 100644 src/gnu/trove/iterator/TFloatDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TFloatFloatIterator.java create mode 100644 src/gnu/trove/iterator/TFloatIntIterator.java create mode 100644 src/gnu/trove/iterator/TFloatIterator.java create mode 100644 src/gnu/trove/iterator/TFloatLongIterator.java create mode 100644 src/gnu/trove/iterator/TFloatObjectIterator.java create mode 100644 src/gnu/trove/iterator/TFloatShortIterator.java create mode 100644 src/gnu/trove/iterator/TIntByteIterator.java create mode 100644 src/gnu/trove/iterator/TIntCharIterator.java create mode 100644 src/gnu/trove/iterator/TIntDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TIntFloatIterator.java create mode 100644 src/gnu/trove/iterator/TIntIntIterator.java create mode 100644 src/gnu/trove/iterator/TIntIterator.java create mode 100644 src/gnu/trove/iterator/TIntLongIterator.java create mode 100644 src/gnu/trove/iterator/TIntObjectIterator.java create mode 100644 src/gnu/trove/iterator/TIntShortIterator.java create mode 100644 src/gnu/trove/iterator/TIterator.java create mode 100644 src/gnu/trove/iterator/TLongByteIterator.java create mode 100644 src/gnu/trove/iterator/TLongCharIterator.java create mode 100644 src/gnu/trove/iterator/TLongDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TLongFloatIterator.java create mode 100644 src/gnu/trove/iterator/TLongIntIterator.java create mode 100644 src/gnu/trove/iterator/TLongIterator.java create mode 100644 src/gnu/trove/iterator/TLongLongIterator.java create mode 100644 src/gnu/trove/iterator/TLongObjectIterator.java create mode 100644 src/gnu/trove/iterator/TLongShortIterator.java create mode 100644 src/gnu/trove/iterator/TObjectByteIterator.java create mode 100644 src/gnu/trove/iterator/TObjectCharIterator.java create mode 100644 src/gnu/trove/iterator/TObjectDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TObjectFloatIterator.java create mode 100644 src/gnu/trove/iterator/TObjectIntIterator.java create mode 100644 src/gnu/trove/iterator/TObjectLongIterator.java create mode 100644 src/gnu/trove/iterator/TObjectShortIterator.java create mode 100644 src/gnu/trove/iterator/TPrimitiveIterator.java create mode 100644 src/gnu/trove/iterator/TShortByteIterator.java create mode 100644 src/gnu/trove/iterator/TShortCharIterator.java create mode 100644 src/gnu/trove/iterator/TShortDoubleIterator.java create mode 100644 src/gnu/trove/iterator/TShortFloatIterator.java create mode 100644 src/gnu/trove/iterator/TShortIntIterator.java create mode 100644 src/gnu/trove/iterator/TShortIterator.java create mode 100644 src/gnu/trove/iterator/TShortLongIterator.java create mode 100644 src/gnu/trove/iterator/TShortObjectIterator.java create mode 100644 src/gnu/trove/iterator/TShortShortIterator.java create mode 100644 src/gnu/trove/iterator/hash/TObjectHashIterator.java create mode 100644 src/gnu/trove/list/TByteList.java create mode 100644 src/gnu/trove/list/TCharList.java create mode 100644 src/gnu/trove/list/TDoubleList.java create mode 100644 src/gnu/trove/list/TFloatList.java create mode 100644 src/gnu/trove/list/TIntList.java create mode 100644 src/gnu/trove/list/TLinkable.java create mode 100644 src/gnu/trove/list/TLinkableAdapter.java create mode 100644 src/gnu/trove/list/TLongList.java create mode 100644 src/gnu/trove/list/TShortList.java create mode 100644 src/gnu/trove/list/array/TByteArrayList.java create mode 100644 src/gnu/trove/list/array/TCharArrayList.java create mode 100644 src/gnu/trove/list/array/TDoubleArrayList.java create mode 100644 src/gnu/trove/list/array/TFloatArrayList.java create mode 100644 src/gnu/trove/list/array/TIntArrayList.java create mode 100644 src/gnu/trove/list/array/TLongArrayList.java create mode 100644 src/gnu/trove/list/array/TShortArrayList.java create mode 100644 src/gnu/trove/list/linked/TByteLinkedList.java create mode 100644 src/gnu/trove/list/linked/TCharLinkedList.java create mode 100644 src/gnu/trove/list/linked/TDoubleLinkedList.java create mode 100644 src/gnu/trove/list/linked/TFloatLinkedList.java create mode 100644 src/gnu/trove/list/linked/TIntLinkedList.java create mode 100644 src/gnu/trove/list/linked/TLinkedList.java create mode 100644 src/gnu/trove/list/linked/TLongLinkedList.java create mode 100644 src/gnu/trove/list/linked/TShortLinkedList.java create mode 100644 src/gnu/trove/map/TByteByteMap.java create mode 100644 src/gnu/trove/map/TByteCharMap.java create mode 100644 src/gnu/trove/map/TByteDoubleMap.java create mode 100644 src/gnu/trove/map/TByteFloatMap.java create mode 100644 src/gnu/trove/map/TByteIntMap.java create mode 100644 src/gnu/trove/map/TByteLongMap.java create mode 100644 src/gnu/trove/map/TByteObjectMap.java create mode 100644 src/gnu/trove/map/TByteShortMap.java create mode 100644 src/gnu/trove/map/TCharByteMap.java create mode 100644 src/gnu/trove/map/TCharCharMap.java create mode 100644 src/gnu/trove/map/TCharDoubleMap.java create mode 100644 src/gnu/trove/map/TCharFloatMap.java create mode 100644 src/gnu/trove/map/TCharIntMap.java create mode 100644 src/gnu/trove/map/TCharLongMap.java create mode 100644 src/gnu/trove/map/TCharObjectMap.java create mode 100644 src/gnu/trove/map/TCharShortMap.java create mode 100644 src/gnu/trove/map/TDoubleByteMap.java create mode 100644 src/gnu/trove/map/TDoubleCharMap.java create mode 100644 src/gnu/trove/map/TDoubleDoubleMap.java create mode 100644 src/gnu/trove/map/TDoubleFloatMap.java create mode 100644 src/gnu/trove/map/TDoubleIntMap.java create mode 100644 src/gnu/trove/map/TDoubleLongMap.java create mode 100644 src/gnu/trove/map/TDoubleObjectMap.java create mode 100644 src/gnu/trove/map/TDoubleShortMap.java create mode 100644 src/gnu/trove/map/TFloatByteMap.java create mode 100644 src/gnu/trove/map/TFloatCharMap.java create mode 100644 src/gnu/trove/map/TFloatDoubleMap.java create mode 100644 src/gnu/trove/map/TFloatFloatMap.java create mode 100644 src/gnu/trove/map/TFloatIntMap.java create mode 100644 src/gnu/trove/map/TFloatLongMap.java create mode 100644 src/gnu/trove/map/TFloatObjectMap.java create mode 100644 src/gnu/trove/map/TFloatShortMap.java create mode 100644 src/gnu/trove/map/TIntByteMap.java create mode 100644 src/gnu/trove/map/TIntCharMap.java create mode 100644 src/gnu/trove/map/TIntDoubleMap.java create mode 100644 src/gnu/trove/map/TIntFloatMap.java create mode 100644 src/gnu/trove/map/TIntIntMap.java create mode 100644 src/gnu/trove/map/TIntLongMap.java create mode 100644 src/gnu/trove/map/TIntObjectMap.java create mode 100644 src/gnu/trove/map/TIntShortMap.java create mode 100644 src/gnu/trove/map/TLongByteMap.java create mode 100644 src/gnu/trove/map/TLongCharMap.java create mode 100644 src/gnu/trove/map/TLongDoubleMap.java create mode 100644 src/gnu/trove/map/TLongFloatMap.java create mode 100644 src/gnu/trove/map/TLongIntMap.java create mode 100644 src/gnu/trove/map/TLongLongMap.java create mode 100644 src/gnu/trove/map/TLongObjectMap.java create mode 100644 src/gnu/trove/map/TLongShortMap.java create mode 100644 src/gnu/trove/map/TMap.java create mode 100644 src/gnu/trove/map/TObjectByteMap.java create mode 100644 src/gnu/trove/map/TObjectCharMap.java create mode 100644 src/gnu/trove/map/TObjectDoubleMap.java create mode 100644 src/gnu/trove/map/TObjectFloatMap.java create mode 100644 src/gnu/trove/map/TObjectIntMap.java create mode 100644 src/gnu/trove/map/TObjectLongMap.java create mode 100644 src/gnu/trove/map/TObjectShortMap.java create mode 100644 src/gnu/trove/map/TShortByteMap.java create mode 100644 src/gnu/trove/map/TShortCharMap.java create mode 100644 src/gnu/trove/map/TShortDoubleMap.java create mode 100644 src/gnu/trove/map/TShortFloatMap.java create mode 100644 src/gnu/trove/map/TShortIntMap.java create mode 100644 src/gnu/trove/map/TShortLongMap.java create mode 100644 src/gnu/trove/map/TShortObjectMap.java create mode 100644 src/gnu/trove/map/TShortShortMap.java create mode 100644 src/gnu/trove/map/custom_hash/TObjectByteCustomHashMap.java create mode 100644 src/gnu/trove/map/custom_hash/TObjectCharCustomHashMap.java create mode 100644 src/gnu/trove/map/custom_hash/TObjectDoubleCustomHashMap.java create mode 100644 src/gnu/trove/map/custom_hash/TObjectFloatCustomHashMap.java create mode 100644 src/gnu/trove/map/custom_hash/TObjectIntCustomHashMap.java create mode 100644 src/gnu/trove/map/custom_hash/TObjectLongCustomHashMap.java create mode 100644 src/gnu/trove/map/custom_hash/TObjectShortCustomHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteObjectHashMap.java create mode 100644 src/gnu/trove/map/hash/TByteShortHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharObjectHashMap.java create mode 100644 src/gnu/trove/map/hash/TCharShortHashMap.java create mode 100644 src/gnu/trove/map/hash/TCustomHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleObjectHashMap.java create mode 100644 src/gnu/trove/map/hash/TDoubleShortHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatObjectHashMap.java create mode 100644 src/gnu/trove/map/hash/TFloatShortHashMap.java create mode 100644 src/gnu/trove/map/hash/THashMap.java create mode 100644 src/gnu/trove/map/hash/TIntByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TIntCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TIntDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TIntFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TIntIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TIntLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TIntObjectHashMap.java create mode 100644 src/gnu/trove/map/hash/TIntShortHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongObjectHashMap.java create mode 100644 src/gnu/trove/map/hash/TLongShortHashMap.java create mode 100644 src/gnu/trove/map/hash/TObjectByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TObjectCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TObjectDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TObjectFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TObjectIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TObjectLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TObjectShortHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortByteHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortCharHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortDoubleHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortFloatHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortIntHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortLongHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortObjectHashMap.java create mode 100644 src/gnu/trove/map/hash/TShortShortHashMap.java create mode 100644 src/gnu/trove/procedure/TByteByteProcedure.java create mode 100644 src/gnu/trove/procedure/TByteCharProcedure.java create mode 100644 src/gnu/trove/procedure/TByteDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TByteFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TByteIntProcedure.java create mode 100644 src/gnu/trove/procedure/TByteLongProcedure.java create mode 100644 src/gnu/trove/procedure/TByteObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TByteProcedure.java create mode 100644 src/gnu/trove/procedure/TByteShortProcedure.java create mode 100644 src/gnu/trove/procedure/TCharByteProcedure.java create mode 100644 src/gnu/trove/procedure/TCharCharProcedure.java create mode 100644 src/gnu/trove/procedure/TCharDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TCharFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TCharIntProcedure.java create mode 100644 src/gnu/trove/procedure/TCharLongProcedure.java create mode 100644 src/gnu/trove/procedure/TCharObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TCharProcedure.java create mode 100644 src/gnu/trove/procedure/TCharShortProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleByteProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleCharProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleIntProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleLongProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TDoubleShortProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatByteProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatCharProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatIntProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatLongProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TFloatShortProcedure.java create mode 100644 src/gnu/trove/procedure/TIntByteProcedure.java create mode 100644 src/gnu/trove/procedure/TIntCharProcedure.java create mode 100644 src/gnu/trove/procedure/TIntDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TIntFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TIntIntProcedure.java create mode 100644 src/gnu/trove/procedure/TIntLongProcedure.java create mode 100644 src/gnu/trove/procedure/TIntObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TIntProcedure.java create mode 100644 src/gnu/trove/procedure/TIntShortProcedure.java create mode 100644 src/gnu/trove/procedure/TLongByteProcedure.java create mode 100644 src/gnu/trove/procedure/TLongCharProcedure.java create mode 100644 src/gnu/trove/procedure/TLongDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TLongFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TLongIntProcedure.java create mode 100644 src/gnu/trove/procedure/TLongLongProcedure.java create mode 100644 src/gnu/trove/procedure/TLongObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TLongProcedure.java create mode 100644 src/gnu/trove/procedure/TLongShortProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectByteProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectCharProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectIntProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectLongProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TObjectShortProcedure.java create mode 100644 src/gnu/trove/procedure/TShortByteProcedure.java create mode 100644 src/gnu/trove/procedure/TShortCharProcedure.java create mode 100644 src/gnu/trove/procedure/TShortDoubleProcedure.java create mode 100644 src/gnu/trove/procedure/TShortFloatProcedure.java create mode 100644 src/gnu/trove/procedure/TShortIntProcedure.java create mode 100644 src/gnu/trove/procedure/TShortLongProcedure.java create mode 100644 src/gnu/trove/procedure/TShortObjectProcedure.java create mode 100644 src/gnu/trove/procedure/TShortProcedure.java create mode 100644 src/gnu/trove/procedure/TShortShortProcedure.java create mode 100644 src/gnu/trove/procedure/array/ToObjectArrayProceedure.java create mode 100644 src/gnu/trove/queue/TByteQueue.java create mode 100644 src/gnu/trove/queue/TCharQueue.java create mode 100644 src/gnu/trove/queue/TDoubleQueue.java create mode 100644 src/gnu/trove/queue/TFloatQueue.java create mode 100644 src/gnu/trove/queue/TIntQueue.java create mode 100644 src/gnu/trove/queue/TLongQueue.java create mode 100644 src/gnu/trove/queue/TShortQueue.java create mode 100644 src/gnu/trove/set/TByteSet.java create mode 100644 src/gnu/trove/set/TCharSet.java create mode 100644 src/gnu/trove/set/TDoubleSet.java create mode 100644 src/gnu/trove/set/TFloatSet.java create mode 100644 src/gnu/trove/set/TIntSet.java create mode 100644 src/gnu/trove/set/TLongSet.java create mode 100644 src/gnu/trove/set/TShortSet.java create mode 100644 src/gnu/trove/set/hash/TByteHashSet.java create mode 100644 src/gnu/trove/set/hash/TCharHashSet.java create mode 100644 src/gnu/trove/set/hash/TCustomHashSet.java create mode 100644 src/gnu/trove/set/hash/TDoubleHashSet.java create mode 100644 src/gnu/trove/set/hash/TFloatHashSet.java create mode 100644 src/gnu/trove/set/hash/THashSet.java create mode 100644 src/gnu/trove/set/hash/TIntHashSet.java create mode 100644 src/gnu/trove/set/hash/TLinkedHashSet.java create mode 100644 src/gnu/trove/set/hash/TLongHashSet.java create mode 100644 src/gnu/trove/set/hash/TShortHashSet.java create mode 100644 src/gnu/trove/stack/TByteStack.java create mode 100644 src/gnu/trove/stack/TCharStack.java create mode 100644 src/gnu/trove/stack/TDoubleStack.java create mode 100644 src/gnu/trove/stack/TFloatStack.java create mode 100644 src/gnu/trove/stack/TIntStack.java create mode 100644 src/gnu/trove/stack/TLongStack.java create mode 100644 src/gnu/trove/stack/TShortStack.java create mode 100644 src/gnu/trove/stack/array/TByteArrayStack.java create mode 100644 src/gnu/trove/stack/array/TCharArrayStack.java create mode 100644 src/gnu/trove/stack/array/TDoubleArrayStack.java create mode 100644 src/gnu/trove/stack/array/TFloatArrayStack.java create mode 100644 src/gnu/trove/stack/array/TIntArrayStack.java create mode 100644 src/gnu/trove/stack/array/TLongArrayStack.java create mode 100644 src/gnu/trove/stack/array/TShortArrayStack.java create mode 100644 src/gnu/trove/strategy/HashingStrategy.java create mode 100644 src/gnu/trove/strategy/IdentityHashingStrategy.java create mode 100644 src/me/Utils.java create mode 100644 src/me/bruce/factions/KIts/GiveBook.java create mode 100644 src/me/bruce/factions/KIts/KitsBook.java create mode 100644 src/me/bruce/factions/KIts/KitsInteract.java create mode 100644 src/me/bruce/factions/KIts/KitsInvClick.java create mode 100644 src/me/bruce/factions/KIts/Kitsgive/GiveKits.java create mode 100644 src/me/bruce/factions/LorexHCF.java create mode 100644 src/me/bruce/factions/armors/PvpClass.java create mode 100644 src/me/bruce/factions/armors/PvpClassManager.java create mode 100644 src/me/bruce/factions/armors/archer/ArcherClass.java create mode 100644 src/me/bruce/factions/armors/archer/ArcherMark.java create mode 100644 src/me/bruce/factions/armors/bard/BardClass.java create mode 100644 src/me/bruce/factions/armors/bard/BardData.java create mode 100644 src/me/bruce/factions/armors/bard/BardEffect.java create mode 100644 src/me/bruce/factions/armors/bard/EffectRestorer.java create mode 100644 src/me/bruce/factions/armors/event/PvpClassEquipEvent.java create mode 100644 src/me/bruce/factions/armors/event/PvpClassUnequipEvent.java create mode 100644 src/me/bruce/factions/armors/miner/MinerClass.java create mode 100644 src/me/bruce/factions/armors/rogue/RogueClass.java create mode 100644 src/me/bruce/factions/commands/.DS_Store create mode 100644 src/me/bruce/factions/commands/BallerRevive.java create mode 100644 src/me/bruce/factions/commands/BanCommand.java create mode 100644 src/me/bruce/factions/commands/BroadCastCommand.java create mode 100644 src/me/bruce/factions/commands/Buy.java create mode 100644 src/me/bruce/factions/commands/CobbleCommand.java create mode 100644 src/me/bruce/factions/commands/CoordsCommand.java create mode 100644 src/me/bruce/factions/commands/Discord.java create mode 100644 src/me/bruce/factions/commands/FRCOMMAND.java create mode 100644 src/me/bruce/factions/commands/FixCommand.java create mode 100644 src/me/bruce/factions/commands/Forums.java create mode 100644 src/me/bruce/factions/commands/FreezeCommand.java create mode 100644 src/me/bruce/factions/commands/GiveCrowbarCommand.java create mode 100644 src/me/bruce/factions/commands/GlowstoneMountain.java create mode 100644 src/me/bruce/factions/commands/GoppleCommand.java create mode 100644 src/me/bruce/factions/commands/HelpCommand.java create mode 100644 src/me/bruce/factions/commands/HubCommand.java create mode 100644 src/me/bruce/factions/commands/InveeSeeCommand.java create mode 100644 src/me/bruce/factions/commands/LFFCommand.java create mode 100644 src/me/bruce/factions/commands/LogoutCommand.java create mode 100644 src/me/bruce/factions/commands/MapKitCommand.java create mode 100644 src/me/bruce/factions/commands/MedicCommand.java create mode 100644 src/me/bruce/factions/commands/OresCommand.java create mode 100644 src/me/bruce/factions/commands/Panic.java create mode 100644 src/me/bruce/factions/commands/PingCommand.java create mode 100644 src/me/bruce/factions/commands/PlayTimeCommand.java create mode 100644 src/me/bruce/factions/commands/PotsCommand.java create mode 100644 src/me/bruce/factions/commands/Pro.java create mode 100644 src/me/bruce/factions/commands/PvPCommand.java create mode 100644 src/me/bruce/factions/commands/RefundCommand.java create mode 100644 src/me/bruce/factions/commands/RegenCommand.java create mode 100644 src/me/bruce/factions/commands/RenameCommand.java create mode 100644 src/me/bruce/factions/commands/ReviveCommand.java create mode 100644 src/me/bruce/factions/commands/RulesCommand.java create mode 100644 src/me/bruce/factions/commands/SPCOMMAND.java create mode 100644 src/me/bruce/factions/commands/SetPrefixCommand.java create mode 100644 src/me/bruce/factions/commands/SettingsCommand.java create mode 100644 src/me/bruce/factions/commands/SpawnCommand.java create mode 100644 src/me/bruce/factions/commands/StaffInformation.java create mode 100644 src/me/bruce/factions/commands/StaffSettings.java create mode 100644 src/me/bruce/factions/commands/StatsCommand.java create mode 100644 src/me/bruce/factions/commands/Store.java create mode 100644 src/me/bruce/factions/commands/TLCommand.java create mode 100644 src/me/bruce/factions/commands/Tablist.java create mode 100644 src/me/bruce/factions/commands/TablistCommand.java create mode 100644 src/me/bruce/factions/commands/ToggleCapzoneEntryCommand.java create mode 100644 src/me/bruce/factions/commands/ToggleLightningCommand.java create mode 100644 src/me/bruce/factions/commands/Vip.java create mode 100644 src/me/bruce/factions/commands/WB.java create mode 100644 src/me/bruce/factions/commands/ZorexDeveloper.java create mode 100644 src/me/bruce/factions/commands/ZorexRevive.java create mode 100644 src/me/bruce/factions/commands/nv.java create mode 100644 src/me/bruce/factions/commands/randomtp.java create mode 100644 src/me/bruce/factions/conquest/ConquestExecutor.java create mode 100644 src/me/bruce/factions/conquest/ConquestSetpointsArgument.java create mode 100644 src/me/bruce/factions/deathban/Deathban.java create mode 100644 src/me/bruce/factions/deathban/DeathbanListener.java create mode 100644 src/me/bruce/factions/deathban/DeathbanManager.java create mode 100644 src/me/bruce/factions/deathban/FlatFileDeathbanManager.java create mode 100644 src/me/bruce/factions/deathban/StaffReviveCommand.java create mode 100644 src/me/bruce/factions/deathban/lives/LivesExecutor.java create mode 100644 src/me/bruce/factions/deathban/lives/args/LivesCheckArgument.java create mode 100644 src/me/bruce/factions/deathban/lives/args/LivesCheckDeathbanArgument.java create mode 100644 src/me/bruce/factions/deathban/lives/args/LivesClearDeathbansArgument.java create mode 100644 src/me/bruce/factions/deathban/lives/args/LivesGiveArgument.java create mode 100644 src/me/bruce/factions/deathban/lives/args/LivesReviveArgument.java create mode 100644 src/me/bruce/factions/deathban/lives/args/LivesSetArgument.java create mode 100644 src/me/bruce/factions/deathban/lives/args/LivesSetDeathbanTimeArgument.java create mode 100644 src/me/bruce/factions/economy/EconomyCommand.java create mode 100644 src/me/bruce/factions/economy/EconomyManager.java create mode 100644 src/me/bruce/factions/economy/FlatFileEconomyManager.java create mode 100644 src/me/bruce/factions/economy/PayCommand.java create mode 100644 src/me/bruce/factions/economy/ShopSignListener.java create mode 100644 src/me/bruce/factions/endoftheworld/EotwCommand.java create mode 100644 src/me/bruce/factions/endoftheworld/EotwHandler.java create mode 100644 src/me/bruce/factions/endoftheworld/EotwListener.java create mode 100644 src/me/bruce/factions/eventutils/CaptureZone.java create mode 100644 src/me/bruce/factions/eventutils/EventExecutor.java create mode 100644 src/me/bruce/factions/eventutils/EventScheduler.java create mode 100644 src/me/bruce/factions/eventutils/EventTimer.java create mode 100644 src/me/bruce/factions/eventutils/EventType.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventCancelArgument.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventCreateArgument.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventDeleteArgument.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventRenameArgument.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventSetAreaArgument.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventSetCapzoneArgument.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventStartArgument.java create mode 100644 src/me/bruce/factions/eventutils/argument/EventUptimeArgument.java create mode 100644 src/me/bruce/factions/eventutils/tracker/ConquestTracker.java create mode 100644 src/me/bruce/factions/eventutils/tracker/EventTracker.java create mode 100644 src/me/bruce/factions/eventutils/tracker/KothTracker.java create mode 100644 src/me/bruce/factions/faction/.DS_Store create mode 100644 src/me/bruce/factions/faction/FactionExecutor.java create mode 100644 src/me/bruce/factions/faction/FactionManager.java create mode 100644 src/me/bruce/factions/faction/FactionMember.java create mode 100644 src/me/bruce/factions/faction/FactionSetDTRArgument.java create mode 100644 src/me/bruce/factions/faction/FactionUser.java create mode 100644 src/me/bruce/factions/faction/FlatFileFactionManager.java create mode 100644 src/me/bruce/factions/faction/LandMap.java create mode 100644 src/me/bruce/factions/faction/args/FactionAcceptArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionAllyArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionAnnouncementArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionChatArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionClaimArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionClaimChunkArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionClaimsArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionCreateArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionDemoteArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionDepositArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionDisbandArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionGuiArugment.java create mode 100644 src/me/bruce/factions/faction/args/FactionHelpArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionHomeArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionInviteArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionInvitesArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionKickArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionLeaderArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionLeaveArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionListArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionMapArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionOpenArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionPromoteArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionRenameArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionSetHomeArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionSettingsArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionShowArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionStuckArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionSubclaimArgumentExecutor.java create mode 100644 src/me/bruce/factions/faction/args/FactionUnallyArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionUnclaimArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionUninviteArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionUnsubclaimArgument.java create mode 100644 src/me/bruce/factions/faction/args/FactionWithdrawArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionClaimForArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionClearClaimsArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionForceDemoteArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionForceJoinArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionForceKickArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionForceLeaderArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionForcePromoteArgument.java create mode 100644 src/me/bruce/factions/faction/args/staff/FactionRemoveArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimAddMemberArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimCreateArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimDelMemberArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimDeleteArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimListArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimMembersArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimRenameArgument.java create mode 100644 src/me/bruce/factions/faction/args/subclaim/FactionSubclaimStartArgument.java create mode 100644 src/me/bruce/factions/faction/claim/Claim.java create mode 100644 src/me/bruce/factions/faction/claim/ClaimHandler.java create mode 100644 src/me/bruce/factions/faction/claim/ClaimSelection.java create mode 100644 src/me/bruce/factions/faction/claim/ClaimWandListener.java create mode 100644 src/me/bruce/factions/faction/claim/Subclaim.java create mode 100644 src/me/bruce/factions/faction/claim/SubclaimWandListener.java create mode 100644 src/me/bruce/factions/faction/event/CaptureZoneEnterEvent.java create mode 100644 src/me/bruce/factions/faction/event/CaptureZoneLeaveEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionChatEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionClaimChangeEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionClaimChangedEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionCreateEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionDtrChangeEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionRelationCreateEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionRelationRemoveEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionRemoveEvent.java create mode 100644 src/me/bruce/factions/faction/event/FactionRenameEvent.java create mode 100644 src/me/bruce/factions/faction/event/PlayerClaimEnterEvent.java create mode 100644 src/me/bruce/factions/faction/event/PlayerFreezeEvent.java create mode 100644 src/me/bruce/factions/faction/event/PlayerJoinFactionEvent.java create mode 100644 src/me/bruce/factions/faction/event/PlayerJoinedFactionEvent.java create mode 100644 src/me/bruce/factions/faction/event/PlayerLeaveFactionEvent.java create mode 100644 src/me/bruce/factions/faction/event/PlayerLeftFactionEvent.java create mode 100644 src/me/bruce/factions/faction/event/cause/ClaimChangeCause.java create mode 100644 src/me/bruce/factions/faction/event/cause/FactionLeaveCause.java create mode 100644 src/me/bruce/factions/faction/struct/ChatChannel.java create mode 100644 src/me/bruce/factions/faction/struct/Raidable.java create mode 100644 src/me/bruce/factions/faction/struct/RegenStatus.java create mode 100644 src/me/bruce/factions/faction/struct/Relation.java create mode 100644 src/me/bruce/factions/faction/struct/Role.java create mode 100644 src/me/bruce/factions/faction/type/CapturableFaction.java create mode 100644 src/me/bruce/factions/faction/type/ClaimableFaction.java create mode 100644 src/me/bruce/factions/faction/type/ConquestFaction.java create mode 100644 src/me/bruce/factions/faction/type/EndPortalFaction.java create mode 100644 src/me/bruce/factions/faction/type/EventFaction.java create mode 100644 src/me/bruce/factions/faction/type/Faction.java create mode 100644 src/me/bruce/factions/faction/type/GlowstoneMountainFaction.java create mode 100644 src/me/bruce/factions/faction/type/KothFaction.java create mode 100644 src/me/bruce/factions/faction/type/PlayerFaction.java create mode 100644 src/me/bruce/factions/faction/type/RoadFaction.java create mode 100644 src/me/bruce/factions/faction/type/SpawnFaction.java create mode 100644 src/me/bruce/factions/faction/type/WarzoneFaction.java create mode 100644 src/me/bruce/factions/faction/type/WildernessFaction.java create mode 100644 src/me/bruce/factions/keysale/keysaleCommand.java create mode 100644 src/me/bruce/factions/keysale/keysaletimer.java create mode 100644 src/me/bruce/factions/koth/KothExecutor.java create mode 100644 src/me/bruce/factions/koth/args/KothHelpArgument.java create mode 100644 src/me/bruce/factions/koth/args/KothNextArgument.java create mode 100644 src/me/bruce/factions/koth/args/KothScheduleArgument.java create mode 100644 src/me/bruce/factions/koth/args/KothSetCapDelayArgument.java create mode 100644 src/me/bruce/factions/listener/.DS_Store create mode 100644 src/me/bruce/factions/listener/AutoSmeltOreListener.java create mode 100644 src/me/bruce/factions/listener/BookDeenchantListener.java create mode 100644 src/me/bruce/factions/listener/BorderListener.java create mode 100644 src/me/bruce/factions/listener/BottledExpListener.java create mode 100644 src/me/bruce/factions/listener/ChatListener.java create mode 100644 src/me/bruce/factions/listener/ColorUtils.java create mode 100644 src/me/bruce/factions/listener/Cooldowns.java create mode 100644 src/me/bruce/factions/listener/CoreListener.java create mode 100644 src/me/bruce/factions/listener/CreativeClickListener.java create mode 100644 src/me/bruce/factions/listener/CreeperFriendlyListener.java create mode 100644 src/me/bruce/factions/listener/Crowbar.java create mode 100644 src/me/bruce/factions/listener/CrowbarListener.java create mode 100644 src/me/bruce/factions/listener/DateTimeFormats.java create mode 100644 src/me/bruce/factions/listener/DeathListener.java create mode 100644 src/me/bruce/factions/listener/DeathMessageListener.java create mode 100644 src/me/bruce/factions/listener/DeathSignListener.java create mode 100644 src/me/bruce/factions/listener/DelayedMessageRunnable.java create mode 100644 src/me/bruce/factions/listener/ElevatorListener.java create mode 100644 src/me/bruce/factions/listener/EndListener.java create mode 100644 src/me/bruce/factions/listener/EntityLimitListener.java create mode 100644 src/me/bruce/factions/listener/EventSignListener.java create mode 100644 src/me/bruce/factions/listener/ExpMultiplierListener.java create mode 100644 src/me/bruce/factions/listener/FactionListener.java create mode 100644 src/me/bruce/factions/listener/FastEverythingListener.java create mode 100644 src/me/bruce/factions/listener/FoundDiamondsListener.java create mode 100644 src/me/bruce/factions/listener/GlowstoneListener.java create mode 100644 src/me/bruce/factions/listener/ItemRemoverListener.java create mode 100644 src/me/bruce/factions/listener/MapkitHandler.java create mode 100644 src/me/bruce/factions/listener/MineListener.java create mode 100644 src/me/bruce/factions/listener/MobFixesListener.java create mode 100644 src/me/bruce/factions/listener/PlayTimeManager.java create mode 100644 src/me/bruce/factions/listener/PortalListener.java create mode 100644 src/me/bruce/factions/listener/PotListener.java create mode 100644 src/me/bruce/factions/listener/ProtectionListener.java create mode 100644 src/me/bruce/factions/listener/SignSubclaimListener.java create mode 100644 src/me/bruce/factions/listener/StaffModeListener.java create mode 100644 src/me/bruce/factions/listener/StrengthListener.java create mode 100644 src/me/bruce/factions/listener/Tuple.java create mode 100644 src/me/bruce/factions/listener/UUIDFetcher.java create mode 100644 src/me/bruce/factions/listener/UnRepairableListener.java create mode 100644 src/me/bruce/factions/listener/UserManager.java create mode 100644 src/me/bruce/factions/listener/VanishListener.java create mode 100644 src/me/bruce/factions/listener/WorldListener.java create mode 100644 src/me/bruce/factions/listener/combatloggers/CombatLogEntry.java create mode 100644 src/me/bruce/factions/listener/combatloggers/CombatLogListener.java create mode 100644 src/me/bruce/factions/listener/combatloggers/CustomEntityRegistration.java create mode 100644 src/me/bruce/factions/listener/combatloggers/LoggerDeathEvent.java create mode 100644 src/me/bruce/factions/listener/combatloggers/LoggerEntity.java create mode 100644 src/me/bruce/factions/listener/combatloggers/LoggerEntityHuman.java create mode 100644 src/me/bruce/factions/listener/combatloggers/LoggerRemovedEvent.java create mode 100644 src/me/bruce/factions/listener/combatloggers/LoggerSpawnEvent.java create mode 100644 src/me/bruce/factions/listener/fixes/ArmorFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/BlockHitFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/BlockJumpGlitchFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/BoatGlitchFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/ColonCommandFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/CreativeClickListener.java create mode 100644 src/me/bruce/factions/listener/fixes/CreatureSpawn.java create mode 100644 src/me/bruce/factions/listener/fixes/EnchantLimitListener.java create mode 100644 src/me/bruce/factions/listener/fixes/EnderChestRemovalListener.java create mode 100644 src/me/bruce/factions/listener/fixes/EnderpearlRefundListener.java create mode 100644 src/me/bruce/factions/listener/fixes/HungerFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/InfinityArrowFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/PearlGlitchListener.java create mode 100644 src/me/bruce/factions/listener/fixes/PearlLandListener.java create mode 100644 src/me/bruce/factions/listener/fixes/PhaseFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/PluginViewListener.java create mode 100644 src/me/bruce/factions/listener/fixes/PortalTrapFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/PotionLimitListener.java create mode 100644 src/me/bruce/factions/listener/fixes/ServerSecurityListener.java create mode 100644 src/me/bruce/factions/listener/fixes/VoidGlitchFixListener.java create mode 100644 src/me/bruce/factions/listener/fixes/WeatherFixListener.java create mode 100644 src/me/bruce/factions/listener/render/BlockFiller.java create mode 100644 src/me/bruce/factions/listener/render/ProtocolLibHook.java create mode 100644 src/me/bruce/factions/listener/render/VisualBlock.java create mode 100644 src/me/bruce/factions/listener/render/VisualBlockData.java create mode 100644 src/me/bruce/factions/listener/render/VisualType.java create mode 100644 src/me/bruce/factions/listener/render/VisualiseHandler.java create mode 100644 src/me/bruce/factions/listener/render/WallBorderListener.java create mode 100644 src/me/bruce/factions/login/Commands.java create mode 100644 src/me/bruce/factions/login/LoginListener1.java create mode 100644 src/me/bruce/factions/prefix/PrefixInv.java create mode 100644 src/me/bruce/factions/prefix/PrefixMenu.java create mode 100644 src/me/bruce/factions/prefix/builder/ItemBuilder1.java create mode 100644 src/me/bruce/factions/prefix/inventory/PrefixInventoryClick.java create mode 100644 src/me/bruce/factions/prefix/inventory/inv_prefixes.java create mode 100644 src/me/bruce/factions/prefix/prefix.java create mode 100644 src/me/bruce/factions/prefix/simplechat/Chat.java create mode 100644 src/me/bruce/factions/rank/RankCommand.java create mode 100644 src/me/bruce/factions/rank/RankExecutor.java create mode 100644 src/me/bruce/factions/rank/args/RankSetArgument.java create mode 100644 src/me/bruce/factions/reboot/rebootCommand.java create mode 100644 src/me/bruce/factions/reboot/reboottimer.java create mode 100644 src/me/bruce/factions/scoreboard/.DS_Store create mode 100644 src/me/bruce/factions/scoreboard/BufferedObjective.java create mode 100644 src/me/bruce/factions/scoreboard/PlayerBoard.java create mode 100644 src/me/bruce/factions/scoreboard/ScoreboardHandler.java create mode 100644 src/me/bruce/factions/scoreboard/SidebarEntry.java create mode 100644 src/me/bruce/factions/scoreboard/SidebarProvider.java create mode 100644 src/me/bruce/factions/scoreboard/helper/ScoreboardHelper.java create mode 100644 src/me/bruce/factions/staff/PlayerVanishEvent.java create mode 100644 src/me/bruce/factions/staff/StaffInventory.java create mode 100644 src/me/bruce/factions/staff/StaffItems.java create mode 100644 src/me/bruce/factions/staff/StaffModeCommand.java create mode 100644 src/me/bruce/factions/staff/StaffPriority.java create mode 100644 src/me/bruce/factions/staff/VanishCommand.java create mode 100644 src/me/bruce/factions/startoftheworld/SotwCommand.java create mode 100644 src/me/bruce/factions/startoftheworld/SotwListener.java create mode 100644 src/me/bruce/factions/startoftheworld/SotwTimer.java create mode 100644 src/me/bruce/factions/timer/GlobalTimer.java create mode 100644 src/me/bruce/factions/timer/PlayerTimer.java create mode 100644 src/me/bruce/factions/timer/Timer.java create mode 100644 src/me/bruce/factions/timer/TimerCooldown.java create mode 100644 src/me/bruce/factions/timer/TimerExecutor.java create mode 100644 src/me/bruce/factions/timer/TimerManager.java create mode 100644 src/me/bruce/factions/timer/args/TimerCheckArgument.java create mode 100644 src/me/bruce/factions/timer/args/TimerSetArgument.java create mode 100644 src/me/bruce/factions/timer/event/TimerClearEvent.java create mode 100644 src/me/bruce/factions/timer/event/TimerExpireEvent.java create mode 100644 src/me/bruce/factions/timer/event/TimerExtendEvent.java create mode 100644 src/me/bruce/factions/timer/event/TimerPauseEvent.java create mode 100644 src/me/bruce/factions/timer/event/TimerStartEvent.java create mode 100644 src/me/bruce/factions/timer/type/ArcherTimer.java create mode 100644 src/me/bruce/factions/timer/type/ClassLoad.java create mode 100644 src/me/bruce/factions/timer/type/CombatTimer.java create mode 100644 src/me/bruce/factions/timer/type/EnderPearlTimer.java create mode 100644 src/me/bruce/factions/timer/type/GappleTimer.java create mode 100644 src/me/bruce/factions/timer/type/InvincibilityTimer.java create mode 100644 src/me/bruce/factions/timer/type/LogoutTimer.java create mode 100644 src/me/bruce/factions/timer/type/StuckTimer.java create mode 100644 src/me/bruce/factions/timer/type/TeleportTimer.java create mode 100644 src/me/bruce/factions/ymls/AThing.java create mode 100644 src/me/bruce/factions/ymls/LangYML.java create mode 100644 src/me/bruce/factions/ymls/SettingsYML.java create mode 100644 src/me/bruceboy/framework/EnableMessage.java create mode 100644 src/me/bruceboy/framework/commands/Fly.java create mode 100644 src/me/bruceboy/framework/commands/Gamemode.java create mode 100644 src/me/bruceboy/framework/commands/ListCommand.java create mode 100644 src/me/bruceboy/framework/commands/Teleport.java create mode 100644 src/me/bruceboy/framework/commands/tphere.java create mode 100644 src/me/bruceboy/tablist/lorexmc/TabList.java create mode 100644 src/me/bruceboy/tablist/lorexmc/TabTask.java create mode 100644 src/me/bruceboy/tablist/lorexmc/utils/Tab.java create mode 100644 src/me/bruceboy/tablist/lorexmc/utils/TabAdapter.java create mode 100644 src/me/bruceboy/tablist/lorexmc/utils/TabTemplate.java create mode 100644 src/me/bruceboy/tablist/lorexmc/utils/main/TabCreator.java create mode 100644 src/me/tablist/api/tabapi/Tab.java create mode 100644 src/me/tablist/api/tablist/Protocol.java create mode 100644 src/me/tablist/api/tablist/Reflex.java create mode 100644 src/me/tablist/api/tablist/Xernos.java create mode 100644 src/me/tablist/api/tablist/adapter/TablistAdapter.java create mode 100644 src/me/tablist/api/tinyprotocol/Reflection.java create mode 100644 src/me/tablist/api/tinyprotocol/TinyProtocol.java create mode 100644 src/org/apache/commons/collections4/ArrayStack.java create mode 100644 src/org/apache/commons/collections4/Bag.java create mode 100644 src/org/apache/commons/collections4/BagUtils.java create mode 100644 src/org/apache/commons/collections4/BidiMap.java create mode 100644 src/org/apache/commons/collections4/BoundedCollection.java create mode 100644 src/org/apache/commons/collections4/BoundedMap.java create mode 100644 src/org/apache/commons/collections4/Closure.java create mode 100644 src/org/apache/commons/collections4/ClosureUtils.java create mode 100644 src/org/apache/commons/collections4/CollectionUtils.java create mode 100644 src/org/apache/commons/collections4/ComparatorUtils.java create mode 100644 src/org/apache/commons/collections4/EnumerationUtils.java create mode 100644 src/org/apache/commons/collections4/Equator.java create mode 100644 src/org/apache/commons/collections4/Factory.java create mode 100644 src/org/apache/commons/collections4/FactoryUtils.java create mode 100644 src/org/apache/commons/collections4/FluentIterable.java create mode 100644 src/org/apache/commons/collections4/FunctorException.java create mode 100644 src/org/apache/commons/collections4/Get.java create mode 100644 src/org/apache/commons/collections4/IterableGet.java create mode 100644 src/org/apache/commons/collections4/IterableMap.java create mode 100644 src/org/apache/commons/collections4/IterableSortedMap.java create mode 100644 src/org/apache/commons/collections4/IterableUtils.java create mode 100644 src/org/apache/commons/collections4/IteratorUtils.java create mode 100644 src/org/apache/commons/collections4/KeyValue.java create mode 100644 src/org/apache/commons/collections4/ListUtils.java create mode 100644 src/org/apache/commons/collections4/ListValuedMap.java create mode 100644 src/org/apache/commons/collections4/MapIterator.java create mode 100644 src/org/apache/commons/collections4/MapUtils.java create mode 100644 src/org/apache/commons/collections4/MultiMap.java create mode 100644 src/org/apache/commons/collections4/MultiMapUtils.java create mode 100644 src/org/apache/commons/collections4/MultiSet.java create mode 100644 src/org/apache/commons/collections4/MultiSetUtils.java create mode 100644 src/org/apache/commons/collections4/MultiValuedMap.java create mode 100644 src/org/apache/commons/collections4/OrderedBidiMap.java create mode 100644 src/org/apache/commons/collections4/OrderedIterator.java create mode 100644 src/org/apache/commons/collections4/OrderedMap.java create mode 100644 src/org/apache/commons/collections4/OrderedMapIterator.java create mode 100644 src/org/apache/commons/collections4/Predicate.java create mode 100644 src/org/apache/commons/collections4/PredicateUtils.java create mode 100644 src/org/apache/commons/collections4/Put.java create mode 100644 src/org/apache/commons/collections4/QueueUtils.java create mode 100644 src/org/apache/commons/collections4/ResettableIterator.java create mode 100644 src/org/apache/commons/collections4/ResettableListIterator.java create mode 100644 src/org/apache/commons/collections4/SetUtils.java create mode 100644 src/org/apache/commons/collections4/SetValuedMap.java create mode 100644 src/org/apache/commons/collections4/SortedBag.java create mode 100644 src/org/apache/commons/collections4/SortedBidiMap.java create mode 100644 src/org/apache/commons/collections4/SplitMapUtils.java create mode 100644 src/org/apache/commons/collections4/Transformer.java create mode 100644 src/org/apache/commons/collections4/TransformerUtils.java create mode 100644 src/org/apache/commons/collections4/Trie.java create mode 100644 src/org/apache/commons/collections4/TrieUtils.java create mode 100644 src/org/apache/commons/collections4/Unmodifiable.java create mode 100644 src/org/apache/commons/collections4/bag/AbstractBagDecorator.java create mode 100644 src/org/apache/commons/collections4/bag/AbstractMapBag.java create mode 100644 src/org/apache/commons/collections4/bag/AbstractSortedBagDecorator.java create mode 100644 src/org/apache/commons/collections4/bag/CollectionBag.java create mode 100644 src/org/apache/commons/collections4/bag/CollectionSortedBag.java create mode 100644 src/org/apache/commons/collections4/bag/HashBag.java create mode 100644 src/org/apache/commons/collections4/bag/PredicatedBag.java create mode 100644 src/org/apache/commons/collections4/bag/PredicatedSortedBag.java create mode 100644 src/org/apache/commons/collections4/bag/SynchronizedBag.java create mode 100644 src/org/apache/commons/collections4/bag/SynchronizedSortedBag.java create mode 100644 src/org/apache/commons/collections4/bag/TransformedBag.java create mode 100644 src/org/apache/commons/collections4/bag/TransformedSortedBag.java create mode 100644 src/org/apache/commons/collections4/bag/TreeBag.java create mode 100644 src/org/apache/commons/collections4/bag/UnmodifiableBag.java create mode 100644 src/org/apache/commons/collections4/bag/UnmodifiableSortedBag.java create mode 100644 src/org/apache/commons/collections4/bag/package-info.java create mode 100644 src/org/apache/commons/collections4/bidimap/AbstractBidiMapDecorator.java create mode 100644 src/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapDecorator.java create mode 100644 src/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapDecorator.java create mode 100644 src/org/apache/commons/collections4/bidimap/DualHashBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/DualLinkedHashBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/TreeBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/UnmodifiableBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMap.java create mode 100644 src/org/apache/commons/collections4/bidimap/package-info.java create mode 100644 src/org/apache/commons/collections4/collection/AbstractCollectionDecorator.java create mode 100644 src/org/apache/commons/collections4/collection/CompositeCollection.java create mode 100644 src/org/apache/commons/collections4/collection/IndexedCollection.java create mode 100644 src/org/apache/commons/collections4/collection/PredicatedCollection.java create mode 100644 src/org/apache/commons/collections4/collection/SynchronizedCollection.java create mode 100644 src/org/apache/commons/collections4/collection/TransformedCollection.java create mode 100644 src/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java create mode 100644 src/org/apache/commons/collections4/collection/UnmodifiableCollection.java create mode 100644 src/org/apache/commons/collections4/collection/package-info.java create mode 100644 src/org/apache/commons/collections4/comparators/BooleanComparator.java create mode 100644 src/org/apache/commons/collections4/comparators/ComparableComparator.java create mode 100644 src/org/apache/commons/collections4/comparators/ComparatorChain.java create mode 100644 src/org/apache/commons/collections4/comparators/FixedOrderComparator.java create mode 100644 src/org/apache/commons/collections4/comparators/NullComparator.java create mode 100644 src/org/apache/commons/collections4/comparators/ReverseComparator.java create mode 100644 src/org/apache/commons/collections4/comparators/TransformingComparator.java create mode 100644 src/org/apache/commons/collections4/comparators/package-info.java create mode 100644 src/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/AllPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/AndPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/AnyPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/CatchAndRethrowClosure.java create mode 100644 src/org/apache/commons/collections4/functors/ChainedClosure.java create mode 100644 src/org/apache/commons/collections4/functors/ChainedTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/CloneTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/ClosureTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/ComparatorPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/ConstantFactory.java create mode 100644 src/org/apache/commons/collections4/functors/ConstantTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/DefaultEquator.java create mode 100644 src/org/apache/commons/collections4/functors/EqualPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/ExceptionClosure.java create mode 100644 src/org/apache/commons/collections4/functors/ExceptionFactory.java create mode 100644 src/org/apache/commons/collections4/functors/ExceptionPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/ExceptionTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/FactoryTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/FalsePredicate.java create mode 100644 src/org/apache/commons/collections4/functors/ForClosure.java create mode 100644 src/org/apache/commons/collections4/functors/FunctorUtils.java create mode 100644 src/org/apache/commons/collections4/functors/IdentityPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/IfClosure.java create mode 100644 src/org/apache/commons/collections4/functors/IfTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/InstanceofPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/InstantiateFactory.java create mode 100644 src/org/apache/commons/collections4/functors/InstantiateTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/InvokerTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/MapTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/NOPClosure.java create mode 100644 src/org/apache/commons/collections4/functors/NOPTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/NonePredicate.java create mode 100644 src/org/apache/commons/collections4/functors/NotNullPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/NotPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/NullIsFalsePredicate.java create mode 100644 src/org/apache/commons/collections4/functors/NullIsTruePredicate.java create mode 100644 src/org/apache/commons/collections4/functors/NullPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/OnePredicate.java create mode 100644 src/org/apache/commons/collections4/functors/OrPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/PredicateDecorator.java create mode 100644 src/org/apache/commons/collections4/functors/PredicateTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/PrototypeFactory.java create mode 100644 src/org/apache/commons/collections4/functors/StringValueTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/SwitchClosure.java create mode 100644 src/org/apache/commons/collections4/functors/SwitchTransformer.java create mode 100644 src/org/apache/commons/collections4/functors/TransformedPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/TransformerClosure.java create mode 100644 src/org/apache/commons/collections4/functors/TransformerPredicate.java create mode 100644 src/org/apache/commons/collections4/functors/TruePredicate.java create mode 100644 src/org/apache/commons/collections4/functors/UniquePredicate.java create mode 100644 src/org/apache/commons/collections4/functors/WhileClosure.java create mode 100644 src/org/apache/commons/collections4/functors/package-info.java create mode 100644 src/org/apache/commons/collections4/iterators/AbstractEmptyIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/AbstractEmptyMapIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/AbstractIteratorDecorator.java create mode 100644 src/org/apache/commons/collections4/iterators/AbstractListIteratorDecorator.java create mode 100644 src/org/apache/commons/collections4/iterators/AbstractMapIteratorDecorator.java create mode 100644 src/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorDecorator.java create mode 100644 src/org/apache/commons/collections4/iterators/AbstractUntypedIteratorDecorator.java create mode 100644 src/org/apache/commons/collections4/iterators/ArrayIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/ArrayListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/BoundedIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/CollatingIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/EmptyIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/EmptyListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/EmptyMapIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/EmptyOrderedIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/EntrySetMapIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/EnumerationIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/FilterIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/FilterListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/IteratorChain.java create mode 100644 src/org/apache/commons/collections4/iterators/IteratorEnumeration.java create mode 100644 src/org/apache/commons/collections4/iterators/IteratorIterable.java create mode 100644 src/org/apache/commons/collections4/iterators/LazyIteratorChain.java create mode 100644 src/org/apache/commons/collections4/iterators/ListIteratorWrapper.java create mode 100644 src/org/apache/commons/collections4/iterators/LoopingIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/LoopingListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/NodeListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/ObjectArrayIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/ObjectArrayListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/ObjectGraphIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/PeekingIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/PermutationIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/PushbackIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/ReverseListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/SingletonIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/SingletonListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/SkippingIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/TransformIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/UniqueFilterIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/UnmodifiableIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/UnmodifiableListIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/UnmodifiableMapIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/UnmodifiableOrderedMapIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/ZippingIterator.java create mode 100644 src/org/apache/commons/collections4/iterators/package-info.java create mode 100644 src/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java create mode 100644 src/org/apache/commons/collections4/keyvalue/AbstractMapEntry.java create mode 100644 src/org/apache/commons/collections4/keyvalue/AbstractMapEntryDecorator.java create mode 100644 src/org/apache/commons/collections4/keyvalue/DefaultKeyValue.java create mode 100644 src/org/apache/commons/collections4/keyvalue/DefaultMapEntry.java create mode 100644 src/org/apache/commons/collections4/keyvalue/MultiKey.java create mode 100644 src/org/apache/commons/collections4/keyvalue/TiedMapEntry.java create mode 100644 src/org/apache/commons/collections4/keyvalue/UnmodifiableMapEntry.java create mode 100644 src/org/apache/commons/collections4/keyvalue/package-info.java create mode 100644 src/org/apache/commons/collections4/list/AbstractLinkedList.java create mode 100644 src/org/apache/commons/collections4/list/AbstractListDecorator.java create mode 100644 src/org/apache/commons/collections4/list/AbstractSerializableListDecorator.java create mode 100644 src/org/apache/commons/collections4/list/CursorableLinkedList.java create mode 100644 src/org/apache/commons/collections4/list/FixedSizeList.java create mode 100644 src/org/apache/commons/collections4/list/GrowthList.java create mode 100644 src/org/apache/commons/collections4/list/LazyList.java create mode 100644 src/org/apache/commons/collections4/list/NodeCachingLinkedList.java create mode 100644 src/org/apache/commons/collections4/list/PredicatedList.java create mode 100644 src/org/apache/commons/collections4/list/SetUniqueList.java create mode 100644 src/org/apache/commons/collections4/list/TransformedList.java create mode 100644 src/org/apache/commons/collections4/list/TreeList.java create mode 100644 src/org/apache/commons/collections4/list/UnmodifiableList.java create mode 100644 src/org/apache/commons/collections4/list/package-info.java create mode 100644 src/org/apache/commons/collections4/map/AbstractHashedMap.java create mode 100644 src/org/apache/commons/collections4/map/AbstractInputCheckedMapDecorator.java create mode 100644 src/org/apache/commons/collections4/map/AbstractIterableMap.java create mode 100644 src/org/apache/commons/collections4/map/AbstractLinkedMap.java create mode 100644 src/org/apache/commons/collections4/map/AbstractMapDecorator.java create mode 100644 src/org/apache/commons/collections4/map/AbstractOrderedMapDecorator.java create mode 100644 src/org/apache/commons/collections4/map/AbstractReferenceMap.java create mode 100644 src/org/apache/commons/collections4/map/AbstractSortedMapDecorator.java create mode 100644 src/org/apache/commons/collections4/map/CaseInsensitiveMap.java create mode 100644 src/org/apache/commons/collections4/map/CompositeMap.java create mode 100644 src/org/apache/commons/collections4/map/DefaultedMap.java create mode 100644 src/org/apache/commons/collections4/map/EntrySetToMapIteratorAdapter.java create mode 100644 src/org/apache/commons/collections4/map/FixedSizeMap.java create mode 100644 src/org/apache/commons/collections4/map/FixedSizeSortedMap.java create mode 100644 src/org/apache/commons/collections4/map/Flat3Map.java create mode 100644 src/org/apache/commons/collections4/map/HashedMap.java create mode 100644 src/org/apache/commons/collections4/map/LRUMap.java create mode 100644 src/org/apache/commons/collections4/map/LazyMap.java create mode 100644 src/org/apache/commons/collections4/map/LazySortedMap.java create mode 100644 src/org/apache/commons/collections4/map/LinkedMap.java create mode 100644 src/org/apache/commons/collections4/map/ListOrderedMap.java create mode 100644 src/org/apache/commons/collections4/map/MultiKeyMap.java create mode 100644 src/org/apache/commons/collections4/map/MultiValueMap.java create mode 100644 src/org/apache/commons/collections4/map/PassiveExpiringMap.java create mode 100644 src/org/apache/commons/collections4/map/PredicatedMap.java create mode 100644 src/org/apache/commons/collections4/map/PredicatedSortedMap.java create mode 100644 src/org/apache/commons/collections4/map/ReferenceIdentityMap.java create mode 100644 src/org/apache/commons/collections4/map/ReferenceMap.java create mode 100644 src/org/apache/commons/collections4/map/SingletonMap.java create mode 100644 src/org/apache/commons/collections4/map/StaticBucketMap.java create mode 100644 src/org/apache/commons/collections4/map/TransformedMap.java create mode 100644 src/org/apache/commons/collections4/map/TransformedSortedMap.java create mode 100644 src/org/apache/commons/collections4/map/UnmodifiableEntrySet.java create mode 100644 src/org/apache/commons/collections4/map/UnmodifiableMap.java create mode 100644 src/org/apache/commons/collections4/map/UnmodifiableOrderedMap.java create mode 100644 src/org/apache/commons/collections4/map/UnmodifiableSortedMap.java create mode 100644 src/org/apache/commons/collections4/map/package-info.java create mode 100644 src/org/apache/commons/collections4/multimap/AbstractListValuedMap.java create mode 100644 src/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java create mode 100644 src/org/apache/commons/collections4/multimap/AbstractMultiValuedMapDecorator.java create mode 100644 src/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java create mode 100644 src/org/apache/commons/collections4/multimap/ArrayListValuedHashMap.java create mode 100644 src/org/apache/commons/collections4/multimap/HashSetValuedHashMap.java create mode 100644 src/org/apache/commons/collections4/multimap/TransformedMultiValuedMap.java create mode 100644 src/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMap.java create mode 100644 src/org/apache/commons/collections4/multimap/package-info.java create mode 100644 src/org/apache/commons/collections4/multiset/AbstractMapMultiSet.java create mode 100644 src/org/apache/commons/collections4/multiset/AbstractMultiSet.java create mode 100644 src/org/apache/commons/collections4/multiset/AbstractMultiSetDecorator.java create mode 100644 src/org/apache/commons/collections4/multiset/HashMultiSet.java create mode 100644 src/org/apache/commons/collections4/multiset/PredicatedMultiSet.java create mode 100644 src/org/apache/commons/collections4/multiset/SynchronizedMultiSet.java create mode 100644 src/org/apache/commons/collections4/multiset/UnmodifiableMultiSet.java create mode 100644 src/org/apache/commons/collections4/multiset/package-info.java create mode 100644 src/org/apache/commons/collections4/overview.html create mode 100644 src/org/apache/commons/collections4/package-info.java create mode 100644 src/org/apache/commons/collections4/queue/AbstractQueueDecorator.java create mode 100644 src/org/apache/commons/collections4/queue/CircularFifoQueue.java create mode 100644 src/org/apache/commons/collections4/queue/PredicatedQueue.java create mode 100644 src/org/apache/commons/collections4/queue/TransformedQueue.java create mode 100644 src/org/apache/commons/collections4/queue/UnmodifiableQueue.java create mode 100644 src/org/apache/commons/collections4/queue/package-info.java create mode 100644 src/org/apache/commons/collections4/sequence/CommandVisitor.java create mode 100644 src/org/apache/commons/collections4/sequence/DeleteCommand.java create mode 100644 src/org/apache/commons/collections4/sequence/EditCommand.java create mode 100644 src/org/apache/commons/collections4/sequence/EditScript.java create mode 100644 src/org/apache/commons/collections4/sequence/InsertCommand.java create mode 100644 src/org/apache/commons/collections4/sequence/KeepCommand.java create mode 100644 src/org/apache/commons/collections4/sequence/ReplacementsFinder.java create mode 100644 src/org/apache/commons/collections4/sequence/ReplacementsHandler.java create mode 100644 src/org/apache/commons/collections4/sequence/SequencesComparator.java create mode 100644 src/org/apache/commons/collections4/sequence/package-info.java create mode 100644 src/org/apache/commons/collections4/set/AbstractNavigableSetDecorator.java create mode 100644 src/org/apache/commons/collections4/set/AbstractSerializableSetDecorator.java create mode 100644 src/org/apache/commons/collections4/set/AbstractSetDecorator.java create mode 100644 src/org/apache/commons/collections4/set/AbstractSortedSetDecorator.java create mode 100644 src/org/apache/commons/collections4/set/CompositeSet.java create mode 100644 src/org/apache/commons/collections4/set/ListOrderedSet.java create mode 100644 src/org/apache/commons/collections4/set/MapBackedSet.java create mode 100644 src/org/apache/commons/collections4/set/PredicatedNavigableSet.java create mode 100644 src/org/apache/commons/collections4/set/PredicatedSet.java create mode 100644 src/org/apache/commons/collections4/set/PredicatedSortedSet.java create mode 100644 src/org/apache/commons/collections4/set/TransformedNavigableSet.java create mode 100644 src/org/apache/commons/collections4/set/TransformedSet.java create mode 100644 src/org/apache/commons/collections4/set/TransformedSortedSet.java create mode 100644 src/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java create mode 100644 src/org/apache/commons/collections4/set/UnmodifiableSet.java create mode 100644 src/org/apache/commons/collections4/set/UnmodifiableSortedSet.java create mode 100644 src/org/apache/commons/collections4/set/package-info.java create mode 100644 src/org/apache/commons/collections4/splitmap/AbstractIterableGetMapDecorator.java create mode 100644 src/org/apache/commons/collections4/splitmap/TransformedSplitMap.java create mode 100644 src/org/apache/commons/collections4/splitmap/package-info.java create mode 100644 src/org/apache/commons/collections4/trie/AbstractBitwiseTrie.java create mode 100644 src/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java create mode 100644 src/org/apache/commons/collections4/trie/KeyAnalyzer.java create mode 100644 src/org/apache/commons/collections4/trie/PatriciaTrie.java create mode 100644 src/org/apache/commons/collections4/trie/UnmodifiableTrie.java create mode 100644 src/org/apache/commons/collections4/trie/analyzer/StringKeyAnalyzer.java create mode 100644 src/org/apache/commons/collections4/trie/analyzer/package-info.java create mode 100644 src/org/apache/commons/collections4/trie/package-info.java create mode 100644 timers.yml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5172429f264de2441865cb4700216d4256da9242 GIT binary patch literal 6148 zcmeH~J!%6%427R!7lt%jx}3%b$PET#pTHLgIFQEJ;E>dF^gR7ES*H$5cmnB-G%I%Z zD|S`@Z2$T80!#olbXV*=%*>dt@PRwdU#I)^a=X5>;#J@&VrHyNnC;iLL0pQvfVyTmjO&;ssLc!1UOG})p;=82 zR;?Ceh}WZ?+UmMqI#RP8R>OzYoz15hnq@nzF`-!xQ4j$Um=RcIKKc27r2jVm&svm< zfC&6E0=7P!4tu^-ovjbA=k?dB`g+i*aXG_}p8zI)6mRKa+;6_1_R^8c3Qa!(fk8n8 H{*=HsM+*^= literal 0 HcmV?d00001 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f6ee7ba --- /dev/null +++ b/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/artifacts/Vengeful_jar.xml b/.idea/artifacts/Vengeful_jar.xml new file mode 100644 index 0000000..e26f9ee --- /dev/null +++ b/.idea/artifacts/Vengeful_jar.xml @@ -0,0 +1,16 @@ + + + $PROJECT_DIR$/out/artifacts/Vengeful_jar + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..1d9a118 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/PermissionsEx_1_23_4.xml b/.idea/libraries/PermissionsEx_1_23_4.xml new file mode 100644 index 0000000..73aaf06 --- /dev/null +++ b/.idea/libraries/PermissionsEx_1_23_4.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spigot.xml b/.idea/libraries/spigot.xml new file mode 100644 index 0000000..e83f80f --- /dev/null +++ b/.idea/libraries/spigot.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..879934c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..d85e4fa --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,595 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1533082544506 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Vengeful:jar + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + Vengeful + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/.project b/bin/.project new file mode 100644 index 0000000..38c4c23 --- /dev/null +++ b/bin/.project @@ -0,0 +1,17 @@ + + + Hcf core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/bin/LICENSE b/bin/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/bin/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/bin/LorexMC/us/utils/BukkitUtils.class b/bin/LorexMC/us/utils/BukkitUtils.class new file mode 100644 index 0000000000000000000000000000000000000000..3c7746ce15dccce1e8e7d6e173b576735f306801 GIT binary patch literal 11413 zcmbVS34B!5)j#KEW?nM6Kv)6J9=umLp{|kjV+yRJx#$@rn1Jq_;6q_9v_U_0Xz=JW4J}5=n`lc z9v)4Fd!u$!c%+J{pgl4e3#UdCHdE&;yKRT2gMnV7U7&g>oT`pT;r{$qN?I1X;Em++VY6G`+h+Wn=7#j_w67fTJAR0-g z0v$j!(TFE7%irD?jl?3UolJRUUh6xQ3=zMb7k)yjYRwHL;)?Q6&95;Ez0F3 zO)F^?426~rdqW-dZ7rR3^{~cVp?a>+N?Nr zdT1)6awhALpxQFPw6@IE--+d_oGh18rKa_?fyuW$4MefKZyNUUu6zo>g&X{I8C`DC zMy8cBQ=m7Tv;$6$q^3=D1-K^c5j%`TT9<=s!+BKNqG>B#iO%7X5j)n;v>`|5nSIj^ zs`ArPx}boVwreV)`GVU{O;^z_WMgu)H)$dXE-7osrGRwYt!aUDtf5+q5QuAM+L|lf zHPsP(ZS^{l!n6^7oL$#78RaFs_GsEGLF5Tu-5D&PCTg*$8Do(v-ZJ^GsgzoP`g>hluv_HDHH{cHPQ!9aXi5s1-$<)#3x&YFiAFUY5;||XWjP(zbVLXX z4Pk3%8^%DPe1WDH3Z*a8w483%^kN~+H>7Q$8liisrk4p_o_SwRM>X9lM4q~qMnmul zO}80FEp5T(Is?V4MB7!;`!$+gYd*F&GtV_cVB%&hcWJ5(qiDeN7K9Io3A_6 z*x0g9bb608T`j@)K268z{pe`YgQ;TH$${`-`hX@c`TX<%ebAx@XP1+hxg;k)H0w-6 z2UjMZppzDjF4vO4MUxgy%q}Zk>S=nI z9zmdl`!PP&iiO64R`ZfI@l5EgUNkL)?km^GEE&bl2-=UB?N5oXsB98xqu&gfM z&or+w60@5}hkNZrhZLPsG{yVE(XMbJBJb(OCFijQCSxLtk3#&M_Efm=u{$=?<;4E-28;f~G~d)% zQj7=c!^t5y#!pYvKQLn>8kiYXyRQ%61TpgnhJp`!G>fl09r-u*kEeNI1Od3 zionn!6#77?W^^PP=?kZ9;KlHe*Fb{%0H6WcJZHKzMoT1uDuOWR8%-qa80_R~Q!ToE zh~hf!$937Av&!=67?nbNuEbS*cqD2|u?}6XC_CVqsMC&cu`?BMx~MYBrAy@NX3=l^ zOwKzq_2v|>oJ4+NzEJZ@MghEe7LuwmCEFBR*y;%<24UgC90mgSNX%3&Md#WoBlNWQ z#oC-2GF?9ly>fP)p=(YmKUeYwi`PS+nN^c1saq2^V!c0NJgNB-Mk%iQhU~tB&GA(8 zXf*oV1%En4SH}d5OeZwJ`7#tlof#)gPU*1*7SMU~#HzRhI#t}}d)c*KbwSb7LG;ik}GIH2SMD<2@N~MF(9c%-mu|8*2nXvm!`cxJ2RUEV! zRlBnkn<+^1ZpjwkKqQ*7F@#;27GfxKaC8gI)>vePG}m$+0wx+6jzHzovOVYT;Kyoq zuf=-+#57K6o>-X6PCz`7)ZEBTP%ssj@WS|+3$!V6V{wb-R+i!`y})3))NR$dA~IR# z+O$AI<0KTW~Tzfn0)($Jdm^#hwMZk!zyIJahO#3F~A?R_(rDkS$EPLWn>v2 zHdD+VKgaob7LPEke^wSv8HL)7KAIE4MM-(#lMs+BS>^^e8z@9hWC~FUZhtDCSwNaq zxC_DQ=_YHE&5)zAt>Ncuet`^Dd2kgbNL*_pv2Zk)l2Su-sn7P>A*hpag9BkrcsM+0 zhvY-m{wzV+np^zhYzN!t7Gq)TnsKFr<`3}wfNUTUA9kowA>>qZdIpkyQ0_tgki{QFeeE*9+3eQ* z5T9`3${C$7qPXW5!ypT7+da-3-Y130yI>e5BZMuc!1%xbwoz?|& zQ1PIIM!8(lh6M#i_^wDYg7r)=7K^9C>5_J_tL&WaV|08(^GEq(&X|+M|2gf=qBguf zF1*Gqel$CAmzx{HHJ*qJMq>H=Q$%dXki9yZ zwrzD^SfXlmue~~kVp?kCpG%ef3#P5^e0!GdPLqM|8ceYKmF8bFmiXSjXgmg3mSnqa z$_k)j!!qTi?q1eG|3i%KGCyW1x743=NN@ zj+jt`u%{GjrNm|_&N2o2~m`QadcQ9YfYMpUhXSN)^rqv(Mu)YiR(t zOMtsjSnSrS+N8u#IN5AsM5kOZoC9VK;{m46HixOuIvO7C?GLX3WVz1GT+`lk89^7T zJzDKmjab_I?;Q65WtU|3SNzhPz{GSSEHQm!; z?yRqp*g20M9382esk5sktD`x8{(pURM7l-IWSov0x24tLXtW)%RW;A2T8ntDWKp+P zb*df>*Az+JryF81J5e1CCzIj?D}BOesUD__XF!(=087CEE1#VdQRAS6gISDvI8pb} zGC3*1n}s(;`FO`Z_tbkK-Zjm^`&{#V9^P?GisuqJ^~8OdY*ORC0DX&TF({W{N9Pyd z?!`U$2rca%qh;f?dVD ziKld9;~4$Ca-4oSNxxCF@2KL^75AL|^$9?mM}NfidI6U1rVHpE+JJMiE9qXG{Jw{- zqxVvr-bXLRxyJ4Ee!Sg>V~!8dCqeT#-A`Y_DcFzcLHY}Qkn`z&F2oVnJbH+i(+RG` ziPcuzci}|pPvE{7zkQj9;P@f^8P2POp{e&Qo-ZE=HrLAI(K;@1~{8@1pq|ioFx;n`FOy_5r-39xnD& zjPtyE&YmfK0E|6GnY9o~v=*wZLzI^xmdo)2fC}13l{mm(kMqAWoIVDOvO67xc%g}N zsK$%980so&=f!|Vfx}*2!b_q09IE9KTs`0x;AH^U%cYPc20K(MKqW9PAkQ;Y#1>8! zo~FzB-=q{3U{8A$_?aB!)drAe&@0gAS5y|YPVfZ};n@iU2hhti4ig$)!x!T&PiuJ{ z+>?>*w3I;$k#W(KjB+Dm92`C9wWDH!EA~~KK1LQG_vB6Rr4<#YJ^dS-D<^pqHgg{4 zZA6p2Q&H)ylU$RBGsyZ$ZdP=LuMou?aF-dtwjlAh!pti%L~H}JRkR&C(7+<7hogh~t$@Vunv?h;$txdTlSIQwyz09)nQ@F;g4qj?o)xO0;6 zLxkg0P%+6U@uuPP8(6ObuU)Q~T*cRO57>wl`~qxg$igo{3it*Nr{&xTWN?Z`R9 zz2n?J&O^Ia6}pXM6+8VCv@&T3u$TFpsLfvyOFFv^D@LB!^h zdYV>xc6lK8CO({&dj-@L`wGYCKE(5pGt?xuxN~cd%Z@^mvB)icA-~9BfdF+vYk-?7 z9_5>l(e=RR=H?CK{E}@Rxf;-Pi3g}P9j8jC>F6=KK$?zj^Ohj-Ue2`5SK>3I1tmTq zUH>>OT7Ha*K>w=sPb=(@1YKlSVV7w;=6W@pd(aj5hq}sh!qP2gaFBL`oM0 zX&*JvHK00xA8K4n{rJUn(Nhyi{BzY%Xl1N^3R0`~Lm08oKr7r&X`0-zV+$6;^f zJK&_Pw1n?u=mNfT`7VANqEg^pKzYyLH&NVa@y!;$eciv%r-0wd?@9xGE$#wzX~m~u z$3t-Q-N$GSZtt7m2ac14r?F|<9Ow2yUO)H`xI9qGA2tJqj(nlES#;3#( zp1=iZ%#*lF5cfZe?1vrMr>A8vhHXR#Av+2#F>r|EkT~`nI-G$HpWsiXt-S@kCG|HU zrao1Pf8)P(czOaYPYh1*7t8K^2Q5a!*U|9xOoP|+K%NYz?hwb%T_}aYGifwfZNh#N ze~Z5jI!NH};7O3(#NXxb!E1s{9`Qyf^nLz8TA@qvL5O@6Ji$LaH^dLSjPvo24QuKB zq|=*s!WbFZhbtEHPbT`yQ`S&=_@Z#++n|;S=`-WoAQSaGe zZ!u<#zk6t#Rbox@znShr)LWCH%eMTI{EBgvH?A!6P&lsUmgGNF>_y}Jd(S>vIqi|1 zG!MdGh!lPi#<80bYcIw`@Df^$S$Qpf3{y_GU<^EpDdtxE%;n{X`BxyuZ$q@d41RpI zG45K&fV6QiMJ+P8&7m7qF`g8-9#D(b5@5F!lTp-6H>;^hEya@;a_W>!K|V+-Q_IwH zWKRn#Rfrbrlla^8lKHaM{^kx?+zI@T;rEhvU~+%E5sLao7^@l;!o37) z*FwBA{LUA2=24!d0%WNw3>ZazsnOF~Z2_>-c}}G#uObiOHE&!soNJmh&uMf4p&18Y uifY1}Qq8IbcYIS_Xxpdus{`s{*mi8cbfX!`o7r+7-AL6v4S;*p+a$+AzF2JO%+2(Xc$I}Vcf7Bb1OWo zo8CKKw@rqW;WoIv%{@!lZD%ytvwVgrV{rE}Ln83F}BC~J1{+mI>@k?gec7ws{NG*G-DXHoTHFd zlIq8k^Rml^=N_(m9zS82Y0n|{tQ(debf)M!Xz-fVBvPSAgTJ|&Q0ecr)>mX8NWpD} z3AskuO;QpZRAiADK@KwtrWwY%5E0dI53>w$i&n)0*CW9c+S`z2Ubp?_5#&)&Fh`?z zD|Dh7iYSp<9P^kKmhM#OQC3;O!heEm{mm*E7B!4vTrgbHu#6Sb9^c(%nCw+WOP}T9 zj^MGX;SnA)D0|%Bk}XNCJJdgrMzXcU-lfM6P2cBDA%K`K1twocuW(O}I^vzZl0R_Y z45PJxHx4%WQCstB%?-VVxnYS{p-RmyidA8nh8&_N2|7tuh|#H#rPIym9xk0C{*^u= zQ0Ww5agNZbwE%RFl9dpPB9BO3CbYmQ$$aSy$uIQTn;!2;SCGMVnLdRZgt{rQw`7@b zWJk$f`GM?*Q`|91=eWzT^%+wS&T*gN7v?wT7tTPI9>IIM9x{Bo_%km$MkV14%_OMC ziDZ^2&e6Suq-2njlds?jo)RXG5}wf)y;6!kCsq-Z$)BN{I1s9GiK-Cl1zBlCE|5Z0 RL5_YzIxl<-YZQy%)x>Lxn_S@Z`)SSa~y5CU8C>mZD&tAdhebwSlYB)?N~;C!*ZRY3{na+PmHHVy>D3i z_3hm!y60vvr7$;&w(Wy~;TXGpok3RNoWCMEbs_YL6p}ycBZb+{Xj?$mP{=(t_btQq z98K8H79;7Wl9j?j3_emJAi2}!cdBVxrrT1em1Dq=Hx`L)t#qkZrU(gSoNC*9I*%mg z3z)$Inah=K4hnAl3p!gEP0JZ2Q{X5;x|`l~|P`Khouj??RS1zdcxuF=VWs^onRP zBRh=HD{(tw;J8{WtdQS0?CF7P+SV|Gn!@s^OTMv&-e6!muHM@oXvYvxgr;g)jN~tm zD(2~J&u>P(V=LS&Ph71=Wm92e^8Hb@h3C>E&vMNJ-8F|M`{V)d%7NxBTeB?N^$)~; zx!^l-ST~|z{l0BkUccWsgEX!cu!7GO=HsOe9TN>@=h><^1XWkK@;cN>t7S{0fMt|r zbhCgZT&5Y1ZO`fHJEpYw#ZzC374b;n&*s+ZN#^cqJUH^YNvB$k*2xXANDMu(e^LEg zjevRlIf|AQ3Y(Utop#?C4mF#vtx$dQi>q+k)W4+lQAo= z3nORvOeav_oNr7tFCxqM4Bp~efSAQOMt*50d)OPil=( z!KACtaQ+t#f>fsb;9XxnAW4VvA~lMXI8)Mj5$%-|w2QCOcHWSdt<7{Qlt@ve8s>e~ z7xtr7tjS|R zjA&Ittz5PC57aTf5SfJEErCVKmtiHiZ5dy_Zd>{ot75@v+m_fAf!byM2hDJd=BZnF d%$84gE3DCN_N#QSbl5t+;?>At19zu#F9B})>oEWT literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/ConcurrentValueOrderedMap.class b/bin/LorexMC/us/utils/ConcurrentValueOrderedMap.class new file mode 100644 index 0000000000000000000000000000000000000000..303e8367eb174d47dec3a86eee673ec3fc0dce34 GIT binary patch literal 3357 zcmb_eYf}?f7=BI?SP0=F2nt?6nks~7ykM(9Rg7AxfUTkN((4jdTv>MMX5(o8LO=Ig zzxS)1saonx$4~7{f0OO>dC!JT!o}NkV0Lrf^Io6leb3py|NZ?B0OP0_h$&=dJ>Pmb zm(Nwoxk_L=qR^v7j_EGv@{Z?P=AvU6NGj~s8@87#SiWsK_V==*(Bern+g(=ZoUOSlSiz)1 zYr$T2&7k5_vCz0XHT&jeq-Wf~@?F!p><0d$sfBBk3&qKE{8MOlJa474rjV|4UyAUk zgN6lCf8`C-B*6ca-IVRx!8wKa$Y@a^k@uFYB;x2xp&LC0_L9vSX4|G+Sh3e;?Q%ds zlh}j4Rw(RCp$#bm2NVv!#{8;TzQ@Xw*dLk>rO=5k;mUTc`O4~|-~u90a+q(bc214R_;j;U}V*=q+0Tks1lP)4h3p@xE0GCP(W;d2e;i z^d)(wuxC4Ec1;_`aMVCnVfZ!35w#SK;21I9&R1RFYAyzjE1Y@Pu1+F{lPR3SIA@CW z>Pc4EJF;Vm@fGWlLig502$<(ADNMWt+KnSd0586?aUF5(g}^MW5J}xm2BtQSk??$p z2xG=;6;ga*8>H*%t7CXaRN6+u<6)F!3#QXDY8Ms8-rRLjn&eUnAK@|yeYM>-eOMK> z;bY7gxY}^aa*9*<1lL%wxkQS3xA8uDM@;8Zm>0cf-&*w^@cfKFFdZ2!-L{+XBVSEC z{eAXBoaM_iZ1vB@3tPCUi;bp@n3Te91r;}l9DT%8qn)myUf>LW_0JyZoS%DUPZ(K^ZV@~#Z>i2S-Ic#Ighuh3NkGGt8l z9buj4b+X`9{E~IWmMiYyj`!;^@uBeJ)U}B^UaAdHoTwMpdUq1rl_sTtR`{Jdk9%NFr(Z@5McP!!(wjeN3OG_N>BK;rysf`L}VI7hs7 zC~N1(NDLiZ^D2qfyQstC2t9o6rbdaDitl}yXXwp5$DZ5I(EkJj{JEb$4?e-*FWinZ z3}}|%vz^ZlI_<;&9S>6?;phVIA6gCRb|8EQ)secDRWk|e^t zvy@G6l|t+#`VHhR7?`9b`-wYYg6Abc6=UosYR)`I?)F&r87|E0RFAGBAD3Jw68(w4 z&_&?@WmjUjsUFLsKe3KkuIe`W6D+A#&M;c&cmPQzKEOMF5C@RKL1Zz+gf6{iDW!}4Y245(iDeSnP zc1kA{_H$1)p;|wSM1m{a!56d(+vQ7qMOibYU-K=2FI5A#2q3@V8(}`2AkhN(s!dJH zmM9`&l&)#{uA#noJWSAK1e!BrPhp9_m>!JKA3u|{L~MAGY-h9lDjQy*Rhy&CQ^;-4 ojJ<%JeSyiRSlQ8(s;fG%TZO{I8rR)SPI~7%wx>_tgXY%%0C@)sivR!s literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/Config.class b/bin/LorexMC/us/utils/Config.class new file mode 100644 index 0000000000000000000000000000000000000000..7741c8fc5059ac8b34f5936a2144015e0fa87345 GIT binary patch literal 2794 zcmbVNSx*~h6g{797~388KnRe9tau>~*%QdpIJhAJvOq};X`8_eW`eODdyMFhsMOcw z2b32c5~+czk*fBEO8qbW2W{!OGlN;9RF#nDTkgHzIrrRq`Qx9Te*th2iyC|i2ZswK zb7>@*sFV{G+sc&_$wGeC%4!HGBnqW$V!ARvZ`p~Ab6hDIwpGX{X04o=NE-_|*V;Q) z2+GB%v0y4R55F`PjYQ7KXA@&~$;xN@6>5vQO4iCNoZ!3F*zRG%vA<8JM~;!04_JB2 zzNv7v=Rer*eK0bi5J(ng%pmHxI{WQHE)0bR9U(L--2Z=3_kX8h*vgxum4#`uG;U1i zoD38)MsC6=S+e&I1NNL%RyZ{Lk;M0h;YXVQJgDIBiA;nD_>c|_K@FW0YL zSqkGYj%qlf(74+|$1!v(Xp2U!Vm_QzINh_2!o%s8X2$N1Y&-Jg3Znxj1j$K-*6l9d zePlu&J+0#mdMLe_pD91J?75E^PX-ZHfCP=}=*3yeYZQz0Qs~_;`W`?YQ)Z|G=XCVp zJYTg7E*gacJ^OHw>|NARgIW>(vW_c~*Knp}8n&5Yu`1L_%?>WvX1>hQ=6=jJGV>!w z(NRnT>#+Ni#j5aG*0d#{Tm2#K+%i@;MPQ!{KvvgrTgT_PLkRS~YuHArAktFOO=?yl zA#e0+xT~N$LVHJHB#{!azF>2C>D;v5lgWOOE{P!>_wj%_m`hgKW>vD@CI!ccj!`^x zIXyAUg-R*IL`6QX5?>n17b`ZkFpUL=%VQl+Fh-PRW6|6S(zZ{KNr9vArH%>P%kB?GxL zl|?*fl;>njISLF(grbfG~yS zT*(tYCvc+|c%6X*yz7gup*0$NkM`&Xbfn`yp=%Ate+9k`97jNd(r{hF zVgAAA>^e4hzw^THUWkpt0M2`y68s9^n&^+X@RkdogR|B-Y;$nwu7QV3;RbHVl_J1PxIyWRooi>fMhx*FxD_Q5?{r=H|Ui+Iaa)sD_8Ew`x7lh#GF;}U6ICc&!? zWVgb*tB?3~@R$s(H>mfo$a-Dw11k*g%9L_SaDWN9!4|kh(QdO{ z?l8@F$!(Crq$tWgvK?YQJz%OwXfY}?osvDqQ%>eIrP%85scKVA;U(rB$x_I%>s_Jh zp=rUt(8V4JsWzDaoK7C~?`R`aLu!#M>*TYF0-M}F(0H_S&Lt+tB=t&;Ukr3^k*Rm` wCN(pO7^WOhZEiphR15##mr&+&Zp{RmZmSKFm0DqQa?P%E);`(8mOU!}0zuC=K>z>% literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/DelayedMessageRunnable.class b/bin/LorexMC/us/utils/DelayedMessageRunnable.class new file mode 100644 index 0000000000000000000000000000000000000000..8cfab8088cbb10a7e4b5081dfb37ad4a95514eba GIT binary patch literal 885 zcma)4T~8B16g{)8U1=8zwM7KK5Y%@4m>1tbAH?`ziXlMi^R}HVL$|YJcE`xiG69V~ z_yhb=#yhh`tCqwx+1`8S+;i@nJKukN{RZF}9{BJW9(GeLKJ4yrlW~*FB;&6{5}k_S zuE??|7W+o2sGkTQWrmGZ$GmSwBboDTa3qE%5t_erg$p1<<-`(bhE?MJg%>K9`6=IX zXIl*ZxDa4ybdRI=5l}LMJFSzaDw`SFK UHc7GNbbo6-h5!Hn literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/DurationFormatter.class b/bin/LorexMC/us/utils/DurationFormatter.class new file mode 100644 index 0000000000000000000000000000000000000000..156377d966859dccb7cfec721f1cd716a66ee7fa GIT binary patch literal 1726 zcmah}TW=dx5dKblS$o+gjhi^&CQc}Y*nxB@ZMnpuC5{tf*OwC8frd*sUY{h}?%L6M zUG+Ec+?NX8E8f~5xe-WJpLyhozrj1A%-P+jRuh42dC!h#zWL@mGxPgDzdi$S6}t*X z7%r5%j<{c0)%!iY@0wOmFZ3Pmn%&NN*Ri?l3P(Yh;p`oLkLwoi?CG`E9bvc((Mqw} zY^*V`5<_^S*4$)>EgP2EG2QD7p-gs*?5o|jh(p7uf-?*=9*j(+8{Ll4cO21i^@eGS zCPir&!&wH!2d*>BmjBZ~rxI{N!#PY)YPVZ4Ez9gt(o88^ii07kA%dt(|GI`ZBz8pd ztjqt-Yfunn7%Q6{QSI9;;WT*55)6rQ*WlI`cTD*n7^BNxT`EGD(~w4-(zyFF+r{$# zYnWru_Jq4BY)&wpJ))K=ZD;-RJXPziLw2f&;T;WcVV+@%Tu$>L>FuCW%|8edvrSak zb{y~Fl7dBs1zYGXr*8;-mmBgzdpe2ZijHvf0(XTJ-M{0W1|9D+q&C+oE5&ND`uR?M zZM9Y{)OQ-2E5$Myh|Cbz#=awX+fykg6MmrKiUb%x0ifa@c!8+@nWTZYSBXHVw`+}Ia1sJ88O4-Nkn-KDm9Wk)pS-q5gv z?-@pY@sF1X!+fT6f?MtsU5H&f*gRCd>u}RzI8%4Iaks(`f+1Av-M(XpbyJRM@;Hg# z3$&>&$u_~8G(sU-aU)2{>8DdlPC7lqh|xz5ze;bPdS1ZfAzo7l82?3{rukYk)C{32N-j~wxm ze3kTc_y})5rsD|Z0#TNjqh5H@%c&sa6++I)Vu5TDXg&b?lZp#dL~Z&ZGU-E1KKKc9 zGY=6z#Ji6WJ;db!u0F?7`iBWD-yPuk{>mTTse(Se>?9+!Q^xSvGlFX7ic{K05%f08G zd+vRQPdO zIceoJH20TH<*lR9hb(hsk9E|_i_47~ss~evj9Dn=Ee#t!Yi}o^C!)i}k&#p(YGn$k z!en%}aivJF0NZ%w)2K@URum6w_%xR$!%$+cd0`As~EsdytM5Vj_)#14Sx-ySfgXLh9$R3se#X7tp+_|73_@G zwN|2Xaw;b8HZTvh%uFGfVuDuo|9^#33yrtV2eV7B_s$VJ^+HY0ADcTb?z;@=@OgU- z78(D%J;VQY250x#gH8WYPcC&m;Vg~Y14?qVTu&(t^9BoMY-GT+v;CCoHI7p(0QF)Js^)A6u|#pO+QsA02m;Sna)(YGImV2Wgh zuak_ET`7!1h#RnQlnuqq<*ZDc8md&+?A8j!&T+WWhopwuaB3_pwUo`U16X4An1K;d zn6Hqv5BPBaCfgeMtd1qw_!v@7xGYbG23M0gn>zXfdNoGDtDgNZOW3y<;QVC$Crq(OxS=~NE&zoU#1DlgXxw1 z%G8qvhVY=2&r=3Y;U2=LcO?w*^i>02!!8<|owU^=`@dn}o6^#J1fllJ`}!nc zVUYJVBhO{WeE7X|J%wV_oK)2yHwz26kQ%qzefR^z?aPdt=~Uc7>%%8fnWM!qbql33 z;k?vEcy)WbF!5($;xEF))>|{di+M0x%*U+WRGK+nMDFK)ZnTT?v7Cu;vpZJ7FSjs9 ze(9@x2Ia=!Y7NIO7<^~D=XfDk=Oe(C1$>SgyvPjWiwd*P~-|)_OH5xws&!7WYuM~Yj_vy%61pg zqFApYkQzc+Oeo6+YjSaZR@wt*u`Kx*x3or0#qxGuU`Vz`& zY{U}hgoG()JdKR948*UTH4sRnI%e3LN=))=#xd{@vL<03YJA^+5uNVN^SJ+QbcRBK zrDqYULw9Iug#Xu}hrfwBY>AydkK03mfLh%)yV`57-YctmU_mIk>!hZIXy}8p*DeY! zw<3Nia|kpupG!&5GTenQcJaBJ?*~aqnW#g!Pi5VQLEO)ghJK!m!gCch+BLH3(%2w$ z4DhA7^2M!Q+_Iv%nO#<{6Y8@BQAHyy?#_VT74UbT$C9SzBV9z=9P;E|fbKnyD*Z@z zQ{%a7{|ZS0Y}B?~ZYNK7@FS{Kp^Vt3h+MSk;`{>&rH2vi;mAc^n~B{^8-jcZsy-!h zO?!ZVnPHBIUw$-c;SR(T%#dVbP2?TiIgPy^A=!uM4 zCipXr)Fq@pT=gao*Ddl&!9yb&aFH8iq2e^e5na(5@n?bFap$ZB`na zXi>oEkz@!n9tJwvN2wLW~`EBHO~qq@Mi|*3($aB|Lh)z4fXT$_nt8 z?D=W$i?pNhl9&b8<1pom)P|;RVy%-(>#9KKD_QfE&`p-mZF11*k=mO<>tQ&XD~!zz zRiL@#O1DGR!pwj)r_q+SSnUiRJKf=lOyeu}cpJQzaZ*Ev9;x?CW2(bfuh;utfzjZt z_g%)ov_$HC)A;UGqAjLI&rM}FR5y5+R6lbW zKX9R3W9`cMHcEdxTTn0SZU@WdUh1|FYgkJgsK)`8#V`vaP5lbvdnf?{E^#!97Zu|& zC)`UR#qbho@X+SNs&#p3c?d6aPN)5Tyuy)>R%`GoPgE<_*TZ#St3WLtT+3hAKbLo#M<7H5{A4kB>-2RyOcKq8Z{1@SutzY@2an z@UWxU4Oaf`_A_F0@jrf`Ic}4V+Z8vsJvGPg@Y8Qx=XF259-!BQ6<$}Ayf&A-E^@qT zcpVoUuYC#yV9@K&LucWsy5KJN8N1OxQXw>>lo7*Gt&}VOg(?@|>v+R4dmj}i9L`g< z_57Ke+KpA%oma9uiPZVfH+lhLvJPsi@z&`a>RFGxR^mR=QaKZo_98NBI9b~W*? zdJTFNTc=yKsJGdoLeqFBc!~XqiyX2`&ERqq?_jxFX7J0drWfIFDtO{N)l?=RLYV;x zdQCE6$56*l@(@MZLK$x1b2}SKA98H9$5k+P6FyuD=CEqVa*Ma)H!9^1@Z;dOY9s*$ z;q_j{GOb7ZFP2|LkOM}_Pg5t}$H}5}ypGTrC!*l*2%LA}IRpaTe8vNM^2m8CRu|xW zUUY%^aj(pH0t?D<*w=57UjpM5q<55Xb~u-XV5)}4*P|_7uvwt+``LkVh9n4-9fVR# z;^%Vw@hr!GEO8uYo5r7PqV0PZ)ge#Pp}f6}t&wbiy(+*WUCrlOJjU;d$JyUbRAAjv X!n&gZD=)M8J=$tQ{3~s^@VEZ~Ug?mR literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/GenericUtils.class b/bin/LorexMC/us/utils/GenericUtils.class new file mode 100644 index 0000000000000000000000000000000000000000..d7cb5ef67f863cbd67a118bd636a77e404bca0f4 GIT binary patch literal 4034 zcmc&%S#uQE75?sQJxiNKAYg2;1{*7qkQjpnh8ZCngxDnH1PKudytJgYXf&FUdwMYP z4%m1j@g5tpRON|0rIHsBMO7rJN|CDkfjp#AdB|&?k}5w@$ltx)Gt)DOrChFZN!5M( zo^#LgopZkK`TMOuUI);LUug&kZ0Il8=Gh}X=~6LWa;#i2eZb6{wl#iCK4=IDtT=6) zG156BKbd}J?6f)V2t>N9yybKY1Y25%1wuWA2{Vo$VmiWz2rTcn^5#Hkdd#$kjIo?4 z(9mBPH*&*93C{>)Ywc8O36@)!mUP zrR6aii49tldBZ8$4Ch!^Z^n1V%`4k|AC|j@db8cPnRjVz7*tRh%y~ojj zn1(e1%c@c-NT3nxbR_YhK-6+f+i(iDz?v3+{D-{#Yy#`?u!aqUvudU+)zO3$Ymqn4 z5~S5-3%7J&!obI_We$(aMjG^`I$bof=hPVvg4z^w@(8^vz+YsxC7WDtgO`jj;Jbe*NL zQy*rvmSiw{b@WK&qE5jT#*s#^%wd0B4&}g@Lo*KQIE2G&1_^>d^F1=~&dO%&*Kq^` z9BgBPsn?)X_An~j@P|5ngrfr5DWf=`I*wE@O4JG-MKt*G@=h`yXLg2lU+I&%eIgH* zoS71XUEvD-lN+}3N)$e0}ik-MiDvbn9G~_gB^L zw{^2Yf@A{r^q^ymPaQF4JmZ>#e9&YfolBrz@41FZc!~yxzC&uF#WFLUBJ5StIA|14 zQ5eT0VhK#4Uqg<$R25VP%YAvf!L6>{DFdXECI$k%_mlKpQJ@*3aIULw34$J8V(%=<#E`O%FooG#r*_IIICk8udtV=%vlBC$}+R6 zZk7;AuwT>hI^N*yI0f~FkaO00!WW%4FHyWjCaj|~Svk7Pq@p-45NPN9ZSupG)Uce5 zlnmpdj(6qs2T8Y4yw7;HDE^bO4|QC^PbgCZwe#-PDo_0Fq0u9ARI|%*RAcEq_K=BEO`75Lf){;Z@^Pns>o_xa}IEzvm)= zIImL7O(b~Ly|s=9_!Pr3ET`5At^-&pjfg)`QyTl}0vblHVfB%=8@SN+7c^eRYi)l< z<3Pte)(T|8S230h&*LGkL&?w$3?)Nz*!VX@uHw*UwVuOcSJ1wB4x2NP1*At7uyv&2 ziEG#{r8^tC=Fpvt@G^%z*RbzT>d=8qq&*p#M_&NPrTJ$Bt}I?@{~aR=scbTg8H_N> zzg5g&9e3NA+g9ebi&=Fsql3(7fcd;cjajV5dFouErbOVNn;ix*#3$y7V;CkXQC!4v z{FpebgM$&Sg0wq~QR;@nis%xbm}%~n>kiPh}5k7`a=D)H^B znXlNmcQvP$uBO~xx|;q2zG_aXY8Eh4spd8$Q>X0K0&G^(8Q^UGpR-xIjQ?^r zOPP=wws5-|xnyV_FAL1$Re_OA{Q8bqa7Xki7LxJC=(dcO)NWw^=A_1 zX;<>a1<4n?ktokODWjzRztZp(gwSwBQpdm@Gj9`gHV(1mJQA_ z$&4qNNoL=-7eD3IdGQi|=x^?fl=iDy-`Rs2` z0QBQK1x*46$4yILnixr!?R42Oigr3%x~Z2O(^}5ymZ235TXPJvq#!Kt(wufvOBc1$ zO#0H)oL+DQng@)M;hYf&C6ZSK!XxIi9z_VPDk5kWcyZh)>67J!Dc!oFO%-*4j&ZY~ z6|ZV^&fk^Eurq7e0?F~`3@0P7ZLz2=>y{tx6?0g#^%MO9nFPJeq^HXB^M;c)s`;cZ z*Kf!quaDOf$~l%%nxWt5=u$ynlsVf9Is{&>*<_1FeMT$h9L>>vt0)AvsEA>!K#SuC z(Z5a*e!Q9F+SA*x9Xl255a@oM3{>pGZkA<6cZRG5(;6{L4r@ms_a&HILl;>`Utj`- z`HT#FkBXNO7uaf4r-v*{TdrYwJh7pl26-shTgMg;T(V(R%>)iKj&gOW1eAi8oFq`K zB7W5(ngl>WQlQgaHq7+!vZK4{Tq-+@Wrw!9wh%=EtqOVtdII=J>Zj!vmopx@>v#3w zkfd~4U`N6WfaXDyO!8_JJvgG`D2|Z|w=80sEm0%kMAln7uHpnv3beUvRSCr^{sOwH z_&TlP6)B=fp=jEaRRRMlUIo?GMxs@-lLsWP4@Yqp!wQB3PRhiVwS{8ZE@|_+JJOdN z-70Ct^ptTsJ>?2TO4UkxqH)J6MsSY4^-_ULQn+N&*2MMU1{H3>n82>rOH#ve$Bf(B zO+7A26t^Y0>_btsx@SaP8!}Qr zH3KE5hW(29sMVE@s-M;z&6^YG3zBjpYOrO5Wn=>J;I>-Z$yTLBOTh*h3#9I+$F)ta zEGM)@w9tHd}W*vUMl28*xoG zMjNMF@IK31YbRd);)SAS+i_=kQD;Ay#RUZ)k&rc7jmY&$(-||%rD>ll6r@x$X<*do z!4%dufncQsTIDWxN}x9w_y#nf0`>+N);K5{ZI^Ar6}kIW8ViW!cq6eqN1tobmsrA_ zS+)xLm?5uMyL`sf-QNyL(9p$Ceu%d}pqV3H(D+pNE6umyJCb^UmcMe)glNSGXhj>x zs%OCWCjM&03wV)MFL4~^O1tZ3ieu@1cj_TFkEb4Co4`YKPDH*(S3cB}%ZGb&_qgtP zf5EkFV;CxZZE{bEd;75u-L#8f8}{P>{mb=(95wM|URc(g{2!hy6ZyeoB=QfC8h?zQ ze9r^)P4uRo+{fWm{*~q@CnBK};lH4LM{_KEbh5YaKKk#3MJybP++BIvdmpEI?j!RM zgZH?*J>N0P{pbJgrhN{hxX92XC@J^Zffj6L+FKZ6jB{IwVGO5ve|r@>XuT6-yqrnk z`k4j;!#F1RZsGbQF1e8P<1*))xI2O$B1ivY+;Ii3bM-214wasx;n;YR|5C3J>x^rku=;b%?!-G3(}I$1U@-d*|k z|3!p1g;j`jF}J-$WFPbHW{LJQ-fo=2K@9NXat=wNk_sSl8B-{@hz$6M9IGJGNgvbD ziO6UjB0CX!hPVfYAPO;wLS8;33O6tlKw(xALPUsx#6R~Kb9vIT_yCJ6uPw<@o)FA& z=^=hK=@KK>7YlRZ_y54#kMPG3TypeP;P@9;{@f?2F`MsrkGntcs4<4~_^^%|hsoz7 z4DBfP;20t3=kpkbc=a2_Nm`%61rkM4;|vAJ(C{%!Efto*C-{`bmwP|M=S*e~VUsY0 zDBZXVNtnAONxrC%q}wA&L_wE=IR*TuB~K~0uTY!Bg^E`gUn{=ESF6Fne=FczYzU6T z=6k&DVbfm2Cg5fc)IUChTs;2Waegm3=`YAo2? literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/InventoryUtils.class b/bin/LorexMC/us/utils/InventoryUtils.class new file mode 100644 index 0000000000000000000000000000000000000000..4704d8b3b018c15fa1b3bc644b7d79b61d4eb031 GIT binary patch literal 5113 zcmb_gTX$2}5&pKNqod1lY%nrWFyNS*EifWZBR~d&u?-fn1wp=GlLU_C6I)o897!fP zy@a+7P1A<9lwP1s6G9WymbM9P9h^2Uc_FKP>096O-2c#(RQ>kR#YYg=U0q#XOWK#2 z*)!iaGkeQ_{nrPJ0KR~aR8$CT>`A4K^SvE`=}cfc8&6~c;p90ZnN6i<`sGxGU7-4` zeohZ0^yFCJ*vMHUmK9jr*>$+Rzo+kXI5N-`={t5}==5N?v#(n~gas-)QprqKPi6=7 z#I#}Kc`kv6d&7}%Z-1{vrMoM9q`Ob<3xV1P_oLzAE~(gla#=-(RD57xDoV3K0bg-9 z8jc+4={nuf-4*RST@+Yn5$HVDf2d4Az_Bl$jAz>fY>iC=0``v7sNseUYc1XlN?VtQggPsioFuxQVY$1?(t_N;(*tAK0NFs3>ZsU&T6HlCuw zSYTv&Vj`Xm#EZ-X!dYW7n$=?ytxYRRII&T{dn_Fvizn-2dNP^H){hwV$>~JGjYqLb zMT5ZRSZXpbmP(B!i~xs|sbpY8&lrK@X(N_Oj>fZb5~^V{wg_mkaU(VnNo6B6A+V>h z=l=9)eQ>4e!6g;j1UCHV_}tivCJlaU7f@n(R2mwaRziiurObed`HBEh*t9&#+>Mjt zq;Z}JUcd4gl_mwf`jpACie{$bn30X@&l#C)sf?oW7fGePG2Fz$@W^zE>xulLJ8ev+ z&KZ(Tfl%WzCl*<6weI)oS%WE-XpM%O20RF1p9*HrGH@16XxI-Xvxi=?LbI%MX62^F zm6OPggE*w3U7*H7SkVa$9q446pxIvieCKppABiX8*%`BJqLRbI8jgU?L8VCF%oG7x zTh3z9RI8Les^LlWXZ5ySrEfS zxv(GZ;tO$V?}g9IhgyExhdXa+R7`A|9JCM*C7zrBei2%EB<@9cyjqMUFeu`dF9T zY?UZnz}HlKRiN1t$;zr4zK+>^^$f&~7X-GJSI-g_CI6%xQ}rTVQSl9d2FrQNNNe~e zUgZTS3%V@O<=b;HMjmtl-`4ONF6Dbs#CSpWK=z_l^whjf%o>vQQ5 z@8b&7oKU4_q6RrB*X0s*L-?VFAIZ{|okwnh&lRlnp=aaY4Gyd|)vsA_pLwW|0z+vk!Fqubmiz4zb--qA28H63*G zNn=LEFBp(1YnlkNn8u8>8#nPQ4Yy=K&UoQ@B^~;WhTq~{Mmer$BIf{(54wE4-ji zSrlk-pJiIoFDzOCE4wo-?w8(AZLMuQ_UQl5oPayZUJ)}6$K`Xdrc`3)b9$$wlyHTU zNh95n&@&l>S+AIBfXCSN&&$}tmleU{u@KE z^Lv+n^@cmBAM`JNh^;-g{d4g7>slh)>zY4?D(0Xz&!aIqTOsQFi`R4i*#0hcY>?+{ zFvG6l=NeSf=4#aPZ!NZPypyNP^ZofVumjDURbmr&n(09mHqw0uL969>7a_Hwg%W#V z{|u{DJT7vSwsRoIDzE;E{34yUEZPdY|D?K$zm=XS1os3D%fLO4R6Ea9yAsu|@mri$ zn11K+S#QC|gCKp8nC-@%ya{oe)Oxsf$-jWTeD&G4&*Q)~sP;M7Z9!#y&@qRU&ps4# zF9uzkEYJ#_ojd30@m2M4^$RaD7YcpklVZ(^q$pRnIRt=~?>hipDI zx`2TS49=m>M`gJ?I**|_RL(ku*Xea#&)uALX%*hCCBqmH;g zMx27!h68BCaWr9w_{XuG_j5BZ&Yk!oWnQN2YlKR&bAsB85YOOQe#_BmoH2pB1RW#9 zORmL;jg68QF-kjjo^~Dvo+Ca!-pP_h2TwkVF@CBhi|63}6gA}Lp!keQWOC_I5mIqb zkj%#g^HzQXIeJvSL#_*Z>vF7)^39@JMUH2xNa@ok~+=`)Kz*FIXiJCsLZOut9qT+bARzF zGPClW_{|e{6NNpjfxXPO5Hr7(xa{L-Ki{%#=;!D(-{BJfZnJ_$O8AeI@EX1R8CSmRI0|t|?WqDQHw&y>vG33GG875f$%Jz;sM=&nHTaxf zM@vZYDfdw0Q^>?^JpVSFvN2W8I)vBZRj=nhsk;Wnc5B^L^!PtQ_A0vkcadGdIf0>& z60-Xg3%Lyza%)U-ttN{^ep0u@<6*)FvQlwVl`DHS=RAX049ACi5C*QK3 z6j}`8OWaj>LVhjJ_Oo#1cz}y6oAn~gsaQB>c_`K$C^_~9NpDej1$lD*WqhT;+6j6o zJH;9QJYMQyCB59c<6}vHt&J<+TEKT?gWR!zAModw;ph! zfVbuN<~)AsRo;Tr-bPZT$gc&i<^H~2G9dGt{|{pK2lHJaLT)1Q5G%WyS-+b3zMlEC zh55K2N%E2+CsX8Ok}PB_RdojM;Wlk3}|Bw!T0GrPu;>g zec!CA{k+5OV1eTgs9#I@ywo2lmEZeQq2faFwyIWfk+|lVB~BF=@-ud~tMXa!23xc& cEXRF2@-F(2)+?}xKl5Aukh;Ma^j(MR-)q3G(f|Me literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/ItemBuilder.class b/bin/LorexMC/us/utils/ItemBuilder.class new file mode 100644 index 0000000000000000000000000000000000000000..04c22d9411eccaf541ac28f8d62c8ea3d13aab3f GIT binary patch literal 3650 zcma)8Yf~H78Geo=v$EJ?Ti6E2G67>_U22OYcIs5b3D_aU0qjHx*rb=Nqz$Z*R#dy9 zCcUI-n>J~4X`4&yFP-Tpe@$i*Fv+wZ+nN5RPSfYzUBn86?a_?1I_Evl`@GM4Is2dg zef3WO=W$0vL?Ja@Z?-VYT%)|KFv!D;`BHOv*>dxiy=vNSy|LyY6vd*T5UZK4p>V3RrEGfUGkl-l-J0->krY+l?ZPrR=<7J~%H5HQ6 z^|Dc&Gl<9k!D7r^vK)nh>HDcce(_qsMBzwBg2L;l@aj`|WDi~wLafWE)tff8R8tDW zZI+#c%*-VaMM{uQC`8klxi}uBOp+{5>cO&M+jV!aWDeTRYBhl&3~M+^<;(S2ez9I( zteSZ~*6Mb?WH@I2dc!Q&?TY1Eb=%Q#3a1tH@{(Czo~^sHgiyGcp5B@J!tRyK?xp=y z;f#)b=!zqw(6^Pp9VFw(adX@gVzAb9JoYPfhn!ZK;US#WaSnNA+T%6eSZvl7PQzo&;r&Z8fl)jmGM?W%K}E03DuxuUnxK16;TdDas}>DUDfEWCY(=NgU9p^% zsCHWGD+kfb5YfCyKP4FqqacgINV_ z$#A5%yxLumo$ESY#7o>^aQ;q`fqC^Nb0|M;Ic`D2%hY;%alFwm)?_DvB2wL$$4w14 zNPOEwc6BV^RkC!fH++v%V)_FeKg5s7z^GKDhNeR7{mI7pqJa{JMxGy*v~^iW1%!)9 zdepp%`!l2iL^T3gwgPp5X+j_r1RsgOVwwuagke@{kFG4^*I zD>8H(kw@Wl8~Lr^cQ`3Xni@JB@Px+F@YB>A)Wmj{q+NPDsKHaFU0yPzWhdK4T(B(N z?Bt*GZRAg3>H!TRiCELIiZ>LVe@MuM2Vkw|Zo}pEQzgjjI+kpPLXLx|$32*rTj~?U)IO?0>5R&}I1L(zJf(Teo z0Cp8I&uKiHOGP(uWG7lLPaXEq27S90T0B4lDfZ(SeF^R(0q%?ZFC-6TH*h?c9Jq(U z`E2e>jBGnd(zTF`p^tI()5){D!;8TBt7Q2gBG?~4J zZ)d;8=*?W}#0DM@yhb4+9VHrYoTpRtdV)R&a0ZWhp0hq?%X7LFVmb(s9&rIrQi|^o zr5BNJ_!ZNjG+a~)cvfhB7lnZ4VxYo6_6v;t8$DV6j;!O-ml%_k+$JU>$bLpBpPVnr zNoqdKoSi1ck&q+H3!+ojk7Nqj_<$-7h_!yw{ke>+HjqJP%SpJR5ijI;5A2f8lZjfBipp C>Mrj9 literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/JavaUtils.class b/bin/LorexMC/us/utils/JavaUtils.class new file mode 100644 index 0000000000000000000000000000000000000000..f6686bde1a3c57b0f09f2ce0557ddf7ecfb261bb GIT binary patch literal 6251 zcmb7I349dQ8UMdzH@EV< z7BB2+Yj3o*Rol{5X%X5Gq_x^s+iLI9+WWF<@9WpoTIm1H%GA&Lb2n_D71&E1{!g%mko#R60dl#H1=%^ORn^dW&of%D``r>O9vs2B?cdaqqt zzgnx`9;)BC?Z#C%)w_o)I9$GBn|o?Gr&g`j2G5yvaanfxO@1swK*3^x*;9mGMGb1{ zbg91)qtojHHcBiIcBf1uKHN|gi zF@0Ezh0Njfs2)!>?}_STDI*aVC`wxHm43=CcU(>&>w9FP=iWr7U_=W_yHi?pXS+7$ z_;^~zRZWSs6^TXp>~it8*U?$6Xj5?Yq)KGJQ_&9AkP^#R8Mb-d)g-xeN_Sl&P!VWy zJIRql+l{0wPI7@ujSSxUC2)IH^kFkSK57>vyrV9G871t{0 z&yxbq5*4q;HiB@w5oh|cdU5SEBN>W~jc9Sk%rv4h+pkxlVUR`DR)_Cn5(QOL>qI`~ z(L_9@8S!LfIL^`^W{no8ag#(?fMs?xlRg3kQF0+$WXr_xc8yv26R?sn%tJ>bNOl5NeJwus4JjDO@gh?RD zcHxp|SI-QZ-6h!1LVLT4TX5j4(&vy&Dn;2EQbhc+98az=4uubI#G4hoi3V9=rZywN zu0%RM#FF36=B?r_xRVHM3AJq;Xxg-y*+0kD^_-fI%!n$eD2~>r5$lA0d--;09y3$yQ!AxO-K603T#p zr4qJrXD5YYvLE;0e%TBkn4%!|$rT?~@ev#%x1^rxW@BYZSQdCC&swp{X~jt0gO92B zI36S_l59X@J*H-G?>5}8n+f87P9|&fQ65(D329JiD#73w@r+ff=>iUuMT-x$CJgqt zC5~gQG7(O&g+*l;8v5P7bi9y*&RMG)T`A(MU6+?bF+Rn{SywILIIiLdjti`vN`rHm z=GDm`&1x-kKUWf6*3gwhddwJ=)pLW+)Ye0?mk4%%+PoBbEfTmUzpi;#_n(*kCHNd3 zSMXQ{q-S|n#pkU;Xe66Q$5MNX@kIgd=AIOokux-8n%dqrBboB!34B??^earr{Hiw8 z^p)Ugd`-bu*+p|aB)N*O;~VS_Nn;T-p2e?dur@ZPOPIXOmit^&8;bF~fVY|%Mwp+% zy{yn#?6Ee;4Ts&x%3R2k?&m(y6VsCHIm)2zw(OBGkC^P<(?X1-&x=B;V(kd0s9UXm zB=NZSjPoZIUM8phq2izT7kv=rE-plsJPdl+j~DThg8yXDXQ?Iow-%*iRs0vHsl1VF zGKLL{CS1dv;we^hJSzkb5CNVSEzIRHh|EQyDm;=$v5{=k<4q3 zn`G<_M8Y*vb>UY%+0@(BEoUxO#UeSQv`0F6d6boN0aeskbKTA1 zO&v|t#A}^#$T3YNdF<^@q|K&#n2*SjhWg+=@DGL4vpqmszXmEP23mBnEkBb%VF|IF{zv6j_sg zi$t{-;BqYILLXM(3eHG%ujRdf_mbKPteimOkv4I}S}bk7ind6Nrdc*k=S(??XILy} z*<{#&u*I?fO=u?NMvf@DMIp5huR=>!P(fBuWCELBMo=XM%_VWw{~@Rg-HxCuC`P)Y zxl+4Kut^u<~FC}Up$-IBH4 za_$2hdpNGCJ%M3?jzgGTe*&Wdk0IG!w`2n8gYbGD;@m!gyU#pdCeMQ0IoK!Bf) zYWR(&7W4VMm~SKis;zL;;3mA5BeJ(tU?(IjU&nA15Huh#r5EI?n|YUEnTdikT;fqM zqOeveJTWksK0@nO$9GE|!;5N*Cve*l(zxBW%w={F?!fE$UQ!=$sMk_2i6vic)ls}* z0&hK=!4(z*8#z9Qfn@P^E1x8*yBt;{WF@n2er@?XCh)G!CvneKM&kX)abH#4I6gFv zkB;M^9RG65&#P(E8bYT5^LWp>YJOJMd`A{JiW2wdYE@RZbz-SbvT9;*H)Du zo4}`~96J+i{H%A`QH%+k;Cm3XkKiQr-_K{;`SRUoIFd4sXJvd=$`BG6GS9cvJ_(ih zcvNr$UsV2uBPa31R%Y^-I_imwr&z3pPT-pb5;AK%Cvj?P-2}c@KaL+C$IsVzs}90n z>7_@0vANP){v7X>9{!Bu1*x+QrHiQovlyS zo-K|&)Dge7U{#6r_ziwbU)1sccbxN(OBH^PKM=0_DaDTM7RPRT{U5nr!mkX4r3I&P zrGlpkKZPyRhd<%ZcEm*$c`01Ai~jI4)PFe$WhVZ5*mspQ`Z)g9QMl4`2(7ghH1O{$ zy%pXG{QDqE>nptDIJ5Z>_%I;~4&qWe=Y_3nipb(_%vn%b#KIS!Ck{b2VBF#-o+60umJbcS$+H%x|zARg(Y_@R-zxP`C+94+gLlV<9WRg z2@JX%xJ#&3N#vImQ7UASt|aXpbWtHQxm#QyQ;_@`MVXjRx3!>3l#`;!$M@D{_NvLxyOaM$Hn%ej1Rfl-m_u09gUP6p~OCx7meRd qVo2cz{@;RquCzHIYUv00cR(zmAMD2AgVLy~e*SU)QpcACqW*v8dLEbn literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/MapSorting$1.class b/bin/LorexMC/us/utils/MapSorting$1.class new file mode 100644 index 0000000000000000000000000000000000000000..dadb3eec8e4ac5b440d7ca9e3560eaf1d1cef2e2 GIT binary patch literal 1137 zcma)5OK;Oa5dNlln4~UA(7vgacPiEKeyf5EhFQC9Sa&3F|bGZtN>bC?5OL zkNbpNt9?$$57dPyBZo~B25u25wlBroWHJ`vJ7*jSLd{mL6P!Dtul0p7A7A1So%L>+ew zGzdExcud^IJ#LaG;x~d(@3t}l7JNBPVnRKW6QQx%vf1=++j?06HzY$iTJ&PMTN(Ju zARL;gVw+GNsU&p8sjqLc@^6ZsYx0DT>s_<|GeQfrtM_{s|*&d4c zQe7B0BJ5o=SOoL6lp-7iP85mAK%20&a+^GN>3rdkdy(T+;MbMo#WT)Yi6x6q;fYIH0Cag zG#bNw>~Y`&_MVr}mVHq56_A=}N9ok1PWLD3UvQw4FJolRsRhX6Q7S!NV0(fl W>v=ro{TZ(s$7!nitD}WZvGfNkpBI4u literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/MapSorting$2.class b/bin/LorexMC/us/utils/MapSorting$2.class new file mode 100644 index 0000000000000000000000000000000000000000..67b19555bc9458f4db87402671a7db6a7eab210c GIT binary patch literal 1139 zcma)5OK;Oa5dNllxJgrzrcI!f(iTF=L&6f`mMRj8S_#RahoIay?#gxLtRp`Vx$=wP z0)hkL%#T9MIzc3gRcdK>XU6mRzS-GdzrX(g@CqFR8-zp459EhI-;6^uj$AJ^2Vy$( zgUD4*iYM3)2(IF)znA(vA$|2}ia+F&*D`JZZ8x@s&9ip)@aIWk;^B2>CNt zxlxahX|_g$Y~R0aV98&AeEcqhi5BvdWm7T!n%uGSaEY;^60T+g}{ zX_t@_)2TNjw3=3eSkuvL8s{nsX5H4@y2OKH3PaaXB8mg9ewi9~wjQ=_>7`}gLJju~ z)Cs#OcuIJHeZr!BJi;dIfB<$k5$ zD}r!bLIpd7;?R!+TVA;OF3bPs=!K?F__*FT>pw%ZK)ZUAccidht;ZK$K3BHqhdkW_ z8D0BV22KeFw~Q8{^hPNe^gR)VGBnU4Y_HrWPhK)%IObktc;)zgWq9$FvsPfq=8b(m|04*pQNeJ zT^4CHhKD%dz(?#oFQF}mpvr45@tFT;d@YXBsSEASPt?BPNGD&$$ea@kki|(NJy~FT YiU#XhJmdX2uPVoBs`{&;iFUs52bMq>X8-^I literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/MapSorting.class b/bin/LorexMC/us/utils/MapSorting.class new file mode 100644 index 0000000000000000000000000000000000000000..61c1ab4200bd7c83d3d3e3732c3929ee6312b535 GIT binary patch literal 2928 zcmcguYg5}s6g|ts!m_}G0BNCVOF~jZ+NhzAwAeVMj!7scwAgV&U#T#Qt5lXelAH-M z{R{msZ8MX&%}jqle^jS;SH_lwcr+gZ1JXY3xp(h5cd!2W_piSJe25>6=Eg?6|&Z*A)ygj6X6S8@grKb$x615wH0Ssp5mm_G+Q>aHF`xFjuNM z4ZZF-b&Kot+Hh=r*YLQ$*0O89>DXC@(L;;sYUzHFVI)_xOxyJH41<}4D#K90+2aZ{ zhKnZzG=D=y3S%15NHQdH5+VtPa~g(`P;mYf`y~|<7!wxL8WbcL(k0X8_galz?pBOl zi!)4=oSI=(4c8Q7IjLe0V-%$Slj#W$Cxl3c)jUcc->Vu{i_`YGOi89tWLG3NyAT?e zOwT8iWZA6ShTn3@|1Y`9aZzO3Udi$#j39QN@2m+T>4s*QohYoD7#^3G1(3 zA&HwBKEbC9s$*|+uVwjL`wVw7G2Z)a&lFz@S*$3?(KXS>rG`9i(OtoXM$4Qoo^up# zZwpOHy{>Bb90dw4sJnvGJP=Y0k+<%1SuAlfN|K&s{AWy5}IFCZ^qP`h6G?auE)Q%Q5_<@Rh_)@_ZDdKoR z9meiy_zK%}X_1m_Z{KlApc}F2K7&4Fs-vk%O3KAassDtM-nlLH$kb`+pjIJCCU#zV z(#7q};QSA+<7%d_s!l$xr1{l)49=*Qot9hUYo=(TX=*N=uZZh{V!C_4X-r}kugMh<2z^R)pmcgNnjc<#j@Nsp2{}0`O|)PG z#WG79lhnd4l7lxT*jqB5+cXv+Ba3ak-Nx15=zUOz5a3)1;f!Dbi?n`?{sLq%^Dd19 za;A&?oSalKnGW`MypSbsqe#&Sf4w!~FIZcn zwIuG~ZrAhrku!bK#%9#pO5d5vs1RQGOl91snIx(q?Q5?;#0Hi3GBIK*_L-jpfj5*33N?5 z6*GxWBvf=`k3j#7Wt(&Ll||FNXDn7tfxR!w@G=?Vq}&b0`XUE{GA3a_4f zH2&!BSVL)2ehM^`NMoOhLA)c7pw*j(U6H=Om(9)Crl+kiC?83yneM9TY7M9<-+pL5 zfde?C;GjURZ6y_lF+`@H`4LPyHVt`xpjy1;z-CjSn7}ZODmX%~W3BI0R55~M0)13k zbKK=w!#0*omniY}=eCI#lQ@BQ6^sfLVy$miQ*jcf1d^mYN-zscXPpIv2poQMx&;PZ zvu4_rn`X75d*;f#QC>D#q_H(pN`k?uI0KEm)AD51H0%b1!1cHSi|0i8u;9@N(!nxR z@jlKA9F#6L-Mi{ZTMJc(j!wncYS&b*l)?uXS8#!*S}K2AYpD1T9|@=oSGQOB$#K^O zvMlcw4Xg1b?59Ywm_iYk6E)_FXP-;)yTcHLVry`T^t;B$Fkd?81yuD6?`9D8>dU#WP6uQ@ej2{l?i zyGw!sxuPtM2GiHs4?&Xzp>lM^JF;!qlM27pXN_m!nI@adpCz)_1#WH2TeG(!MvM9` zhf8yuD0m_;-qL!nJJy;e{F5!Rlf)99$^pQ3DC~Bi>5&?neg%#Kp1G%DGu%{B@eJPx zD00g992Bzc$H$2n4RG4@y@7CpAoh7#5)ZMZ;muTpLx{}!K8^~iG0-XqXFhmB!xQjX3l{W5#HvS;t-E@5- zG;p!&P#4Mk8)q|HSoi^n?>k0+!ayc{;zy*?J(=`qrE=L9`5g})4rdB4@!2N6l=$K@4EHE3nIT5)z5xPmIV9;SM&A5O?lu1X0 znp~s*#SsMudI$K0l^BL{jiJdb^f8pBO;|&(Q0>4keA8MGg%wYsR+X(Gra;N6sQl_bD&&)?T-RVcn@^6X zoXEk0&UoHS9;Vtu@gwoBR6IS|6-gJSnan-=c1Ok{R}V%9!V#u*(eupG%~TT&4b2}@ zyQ_C7vVUM`?^tXwG_;q=AL<<%+qrM&&M0Q|#`eVqBmH5F3r7Zr_l%X_eZvF$`^Q52 zhC+bRGt@iW+Y^e8?dct6vim~2dwa$fGJSmmJF!G08fB_4KaYj_cJ@a4F{rB4R@2)b z8xHjk&-OKUM)yTrYy!yNKQJ5_+Zi3`0n{oWiwt4DNPo{BjOoKnW5XdAd08tSkq{%J zp^?z6kjAcof#KM2WRR&kHW&@X_Amup&BXc!_M&@LPjq0P$UPJZ$A$;`BV*xxG2k>~ z{R8`VhN2}|{o$eB!Lj|JVZq_k7g>kNkbYy~-rXWvw6{;D+!F~6VT#&N|L&pDv60?r zG_+gB)$AUMMEd81^!4@(^!E&fL`L6mZ!}VR_N3#}4)hzH^MhDEn@mr_t`*4%Chmot zVP_`mjK}j17|lb4bUr!lj3jf(M9K-J)0uocpUk9lOv~p@GdBiP1tR_X`dUXqP<)JO z{WY(^tBh^qsbo5t-_BIo-Z8@D>B&qu22~k!IpmuvOghf7nN%i+rTxV8T9dXCma5)X z8r9K04^2s^-bGj)BR&j&ok>+xZIIWX9WY5Mo-NHk;YjmNlf2Sw7zDM~9!zGPqnYgC zTx=$uJuDq|n`B4_pFvjwM52&@a-<<@l201^1`WXbbA{ZDlb(>4t4#7sOTZxUf(d6P zKNXv69x*8(&89)4Fn&IBG#xKw<1+FZlT2xP%{Zx)3_D~}oitenApq3PHif1WNhhrnXH2rBN4-H=I2|N# zN9Ikc7rt%KQAm(X=koD%zC7`9lWb{jFz6!sV@-CAarD3^2Z)38Y^!OCkng+sryrk-TOj<5onhd%Rs#f=K z&G&#wP13T$pm#xlgDH5ufOxk_D}>){&?5kmLNFBedrfK<_DX|(2g*8_$>ei+XGWUd zZ_-L>T4m6OfG;mFu=Af+h8I#sZbI_m{Vd{x& za%MmFXI9#N&!nKVtuyGeKre04l3;&e(mH8cZ_pP2QfAFfWsW$i;V+rAUK%$T^haXl z6n44H_cfC?2*1^!Z-77LAdLwBTPC#%zs;aO!;VA_$sQj`rc&`q7ssEQ)F$m081x<4 zvGJLi1?_)j(go6fp+SEO8It3f^msNtuG{JRCS53P?FRh-ZAf2Ex$PfJYNu*J@MDu+ zO&7ywqsg?>Uzkof*~Jt1bj2%29KOGLF>Qm&6Jw!K`>)bWZ3ncTq35MNy7_GHo!TCy8c*U~Gy zYt9Ym_VaRH;pHZvUUKy_2b$c>D`j&cP0ZS&z5P6ks|mU#O?op259XZw)#WE7j}q^I zI8DjAZLerTrc0Ob#`%6H`%U!JU2^Q=RFP5B4$Mc0Oo(um!(r!DqG~1zx z0Ef88%R8A?%=4ZF-e7W=BLF=fPsbbpU1-1sUAsFD1b8?1dU+31@O*|a`AU|f4)Spd zS)p-$E*wZ4LcGI#P!ei>*K$z)`K>F}|AL%*e8$bYOxw>pdP!}0`6{M{d1{(<8?orj zlp|Jr%>pYfRL*=$%nt3|)iL4;Jx-{=nMX_>;{8mQ{nnF6umg&0d?H!M84Rs8&8`rH z-B8p96HYJ<7xeSBe7%>iV`@FOeNX{SB=sz1@)*BfQu35Dez-rA7cXYovWThXRU)&- zJDX*20?>vOW^fuMrofuP*(skq;s~?}lN~;Y_@fJkvXcd=tff#oaQ18+BL+{wbHh#= zGaNr_LW2*XD(Ow<&(ZGbxs-66dj{I)K~9^T;TeQ`L`$t6n54j(XK&?pdp?T+p3lk9 zZTJ4_GS80Qy6^b;2p{t@4j&gT872GT`KdilYR1W$D1>f6jh0IyrF+_Ub?lNkZZi31 zWshfag6WMWzlr5o0!+xHsOZANev8Ss&9X;@afiuw&N2=N`37j-{@)PI!gcooP1_6owqyvf~L zlaBL4qe_0#^bD8*%lQe0gq#T|uGTu3Oz4TMtMHYml_ zf>K-{D8+?=QrrwE#U+4JocfjGkgpUcd8IhFE5$ioDGugJaSB(8L$^|#ua)9FtrVwc zr8p)l#gSO)x)Q}vSKo28Rf?mmQXE;8;%KTA$55p>azZn<91fM@Xh;=w5uS-&g}-X( zu8YW8DMwPg+qe(9gkA$KB39*3bTm~aULYQ|FRQdSS3XBuo~CX3zTIPA;nDYyzV}qw z;VOOKrSE&H?cQpA->dI^Uc29`?}Pe2WY{r7-}mYJeyiHP+Hyx6P|mfM*S^kj$BZc_ zZW(sMaz{-l=b+`YCoP}OlT^-O%WtPFzjD&bnXv-)8?1nGa>^-KrhUXRm2*rvH&`|H zjaH3vZdT44ty=p{R;_YwRnBczoqfAir<^;L^H$5U@3t)Eyj?l>TJ`ojta|0#ubc-h z+kU5IE9W8QyvJ&=AGR8l^Qdy(XDzcIvz966apio#YP3ISH7e)B$~j>zw?AqvSI)M2qvHd(ybtM zMYWg$gh+U+IKpKklD9ExRJr2@Xqz{8EFVe?Bnu_!(kQGIG2Bf)2&x5Qi z(n}z#iu5^I3i=8D zr*R>N4M~^dlJd3Kk2m4M@zc0n{2?`R3oYk0)WpNIg72bczMEF^leCJzPA&XRTFpPF zHT(-&Td{(I6)S07MJKJV*hCvDwoz-vc518Wrwb|u>B5TFQ+q{%Iw}s~3iTg#Wmz2; z(eA#dYY|VYz_&X$!Ug`R^P*?zr=5+SXX$5iIBoKvM;9W*t8wFdG0?p+^iO;rNOzEhf(|@4XSy4!04rWA609w`g4E^-ecyQGsfr@CeE@8SIN=q>Pg8uUr zP4}}W&X}%y(dm9k|Ahqv%Z(_sy`c4-8(Z6&Jb^%iem4SwJw+5v-wbh16} zfU@}Y^gr|)#amCOA%gU-XU3DLq@FAAB#Nx(N<4|u>)8V}iM+U2D*^coZsP-JYwZ*q zO;t_RP2MJ>(f1rzZS`+_nSCcY@C?^A`%iM?9JX3rBLe5yg}cz*if_i9r;M+)jIXtf zueFS?wT!QoSC#O!atod$t+euLJc)u@6}_QPg5HNUEndTG<)nfem0(GZaikZKv8Hq5 zCTO#*(Q}g5%>j0mc_ls*>{YOrx}D2lYsz42xRu*fnKin!D6>Wt=g|c>lotE|;Q7!N z?A%mRT%-3nzF?~{Pie*?N*jPd2XR?_mEyS8ouiB+SjG`7;|QvP1V>O6Bt{LYf<)k; zq7Ga$=!rjStd)Z zBr;iwUu3crzsO`Mev!#i{34Szy9r^Nt@tk84PJwQnENqr!;6H8+W}B~zZ50}V6%5I zgbC&pnw4igeEUWX6^P0B?W>h$e^Qo&a!W_%)=|8p^y zk@M{sChnG)Q?2ZdGhFS8Sy%IZo)BZ2z0dQG3VN7Yn+;(Y&Hm?kmoOU6>5MOnu{`RG zS_0D)jFrTfmP3e3hvAY*iX-(&GIAqSqO6)kSv85WY7%ADB+9Bul#Q1t84q%mR3lGO z?t{|nC{}XFHY6;G&3^93s%}n^UIS#Pizcb+H2hRt)XRh7q@W=$@1EzVr}2Sq(GKWY z@@4BZ)?BpDthZO-VTfZTFAG%SRXj_6;$2rG){1kQh?#8-JY02>_nqnbZ$MPfs`fhF zzGdy1NB%{@)E_cYbr^Bmu`)!O(46gu&S2;PgE7=;?vmd@MNS`E_CpH_qMwe<3;oH#>?Lb`15-anw{dAlBZ9jCK>U$<1)} zTj)A^BOLxsRG>E_c-%_&f!+`L5a`477WyRJMlYh}i=bZu{Tk>u=nnb;-AO;DyHGv7 z6~)2bTt&BVJ>AT!>0UMd6Rx#pjgMNfRD8hYOZgH{uJK`2z6Wjq*TU1iNZM7v`5k@- zc-27rEymYqgomr>t9(B{0GWpAOZ=cF_XG4CzY|Y>Nbz3Aw`sUv0bj2l!jlOJQkp|* zAjj33Lu!HkQq3WCkRizLM((zBlTDFn?_g^O*Y4ocw2u6`+px>9;gA`;{2omCYpO!y zBUFEOqnka@o#-@{4lL3G!SGkWC%d=3lu_<3Wt5iAjp9f6cdPun{XRG6HdZ6w&Xt~S z8T9~k`yjr%KcJd+Gfc~@rcr;3et{KFQYcA=X(;RQjii{r~!1Ve+4+D zTIp``&fiv#$hI;bD{s8_;{64FY*Z@bGs=X=1-9#qF6{T9?0y)T_7R2c7Bbys*xlu1 z-(61j-Q{H8t)fWm=~huBF?OpclI*+7$-di7_G(arJOQ;P`S^qUp^{*m;arkxafJHO z=-$fCmqxeAF|V(3)hYh)ra4u+RX!_LQK1hvPEVBP=!8;5!G4=NPw^*TCO-GL3b&1) JDka0>{{kx=TGIdk literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/PersistableLocation.class b/bin/LorexMC/us/utils/PersistableLocation.class new file mode 100644 index 0000000000000000000000000000000000000000..62b53cf22d12d4595c1dc8136d725162e1912919 GIT binary patch literal 7060 zcmb7I31FLL8GgQANz;F8m+mM#Sh>0`=^Cyb&~C7{v}|?{(36OVf0u|P2DS?rHQ1JRgwRnXrW_IYE0aL9%Ng|ao? zbzV=<8|wBfTD8XSi`h`5aCSJ-?O7FHyEYK>_`;#pf$n%j-|1XYU zBl57pu27z$-53mq{K8zp9<=x?jG>rGJ_)hv6bjdeBf%~OXZm@k?D4QzA1?Ivl9sbI z#iBhH352?dVAlvs=QU9~^IS~eS;`%rstx?`NNwb2lS2MR?|QD9$+a&K^Ythc)dxa> z*c^q5>U91|`KER#6f}mr{0`(}qJaubBAM!`9d=As7?;4S^m#*}aIA8bzcLgL1|2vK zC)jX2o#PAldb-2m?x3H>?d=VRJgdA>zh`m8Pg{2d#5Yj`C*mXp!`I{Ytz8(7EhGtr zS=DI@oBpaBx-)g?mIG5T)rM+1C5OokxZtMYy8SV2WrfkzQ`2=fZEwdkg~=1V##}GYp&wItXW#DYgrL%ZrnRZc=AT$~n1*agKW1u;Kuw0JLHBfFI%{TCw z#L)^lT3}$bd9=vDVw`6RvRs0PzHb(kb^~KDRtPUO&><*d(Zv!~a=gsIIE+;&Z4HF{ z3*)`3{E;PQN-)lS-e8B9sl^nrHVa}sfv7@ND;@EFbD4I@j8@ZQO-)S_ttzCChZxv8 zc3M%T?YO|(S0{Ih+XLMpZ!8{RnkB+6flxoxS3`H^kc=H8O5jJg4XYJKX#NQr26_;n z?Pwt?nIo>#1HuY*8`fr2EHmZpD0Lu&J{!UcBU4Ny;SF4bh=OBvB;0FaGyl?=SyjVg zmWm`hMmZ42dK=bduxtv)=^_Ig!1__r=Z!@D<`%12F1k%Zs;73`lROTw z>17=|upRf?a32kvR%9D=>o!={A4tV}D!6mhcA6!ctp1GTG-75ck(yA#WKEQRI)L6w zLrWagNv+#upcoDZS5u`PJ}O=EF@^Ct2(t(^Hw*Pbp9~2K)uj6gYo6nr4L*OLZkRUg zp{l72(h~<8XM4P_FC2;ayOOBVw)Yw6$Kz(7OWm=2;=mxDH1L%4_0m306)_#xOCnw$ z2b%*_BXy-M9*PBe{b|JaW1>QypJPTEwE@j$T4AF<=R?72Cn zx61R^%RnUUbG8Eq@w}M$g<%RrhhV&D;0HL&zUA%f^M|?=rsXPFX)dcM%O9~t-n9}4bAg3GTs{$t=MOFYWV*0Lnr8V+?g1Y#7ifcBhEt}4$^ z`Ko}uakX@nCE zm0O{dR%4ja1;pXtC4yMca&vP9net3ePX+WAPo@0mQHe!Ejgj;mVC!oS$0I&}b3k4k zDsp5&tz;r6YZ?i8D1?n=Cr?TbUxxBz2-Qzckow8FP(L~T=_hAB{p4V$pPb(GlVcj6 z<4Lsw$MAbRq5YZzu+p^~6Wq>Y2T|GS9zd0|MpiCa_M_J2dJMIDaI&KOGb~`10QG_~ zrymXSZ0bjgJm>YJRh|p`(I(F&{pfsHOR${Zr)ufTQNY2ogp;L6H;E&pi&D*`TxU_P z7EHh*OhhM7F2u1|!Fyw=IpxIp_$;5Y5_?FHRNw+joBOFvG0&!nHZFHk;%bqwqCn)U zD57*Fv+S-Ck&a(!qE+e3l@#qbn)Y}O%_mTx6EPVl5vpRvpMn}xYjNhFNEju>nWo*M z^qx3Egqt@=oKZw7CHNdwv1_p}w8XyK61&dB(6?MTy04_DMR9w)XU2oc~~Xkqb{f9`GgOek~@8S z(3QuaS|d8Roxub+h+YPZ+Zojx3u+Ev%~p(Z)ev(KF?we^MhX-kz$QX&=jLG$TQU$^ z+|EmeL2S)HWIQ@AO$l?Ej!fs4j2#^a1&|o+U{vyF2by&{4Kjo7pGl+6B6J4dz0O1< z>aY;A8J~0L&a)8UZV+>^o+p=~317lFxPdQWH!+g$z&t#H`FNIZUJ}QZroobKI7sZP z=!RO{jH_`CP5WhH8QL*&b}d(5;m$Y|9VPjE8?1 z0@v@u^~-nT##Xn}#~hxq2Vc)eCmlneegHQo;3(mSL2OIFn+dn1!IuzjO@l8b+%|~Y z6Zl&Qcc$Q7WSy@qX{OX72K-{$^gLR!jaF=@eU@M;|NOLdoOVoQ_#{{nop)QS+CvO2IUB^iQp#A#QsRweaRnJVSX4%{ zj7*?At5{k@9Mc7EOB``QK2#NXJ%}9^?-k@NW*(nbYgly>rIGAXby)LDE-busB-PYl;y4gJWRNOpB8>v`Dx>)b2lF8$4;(x zrt}=CgKiBQ$y%DOH%&iJrhYDRWRId&yQxp}P`g@L*q_*k{fw@s zpCTGa+fHQD?WVF(?!;J^;;c05(v%%z@hqlV&oD8}055_%*G39T-e>qN&b?7=&Zl=D z4lZ{d+Kul~uNedQzVnCt;+jGHW9LuJb;AH&cK*^_x5)Ze=DJnZzc$xx1Ne>eb#vXx zb=d_2`27Ih5>w^rh&4@hF^l462E@f_rt(^1E17Lf0oDDqkrcqgF894CEZE^b0JRN; z`8(V+(t;Y(J@$>Ob)lY8*u??GW zD-C)Z-~DfATHnFjcM%+h%{ znJR~M!Q|A6z4!++I8PVKu_(3KKgMVl%2NItSFHGdtaMzCnU>owV=tDzJZM^UgggfD z&+RD4uP>WCp~p0$Y}0`MlI@j=eOgHNX|#{ceFAjwzvs%m%F43J%~xEtvYwmt^3YAX zI&0Hn*H&`VR!z8VP^k=tor#mq_UJ<5-3#SjV1Zu0O^6 z+fNT3;75_$`bpPoR|5-ZH~*G*_U6-by<}tX@*je=g>mZ@rqn-4s@yR=Fq#ZvrN39DVWoG zQ8HDFz!d}$%rnr z%5u|c&8GD(X}vcLEgABK)+i;U_=X?-{h oEqU`(WpmltAE%!(JNrq(g&r+*4XDxC`J*&Jakx_YB~p$1FQSnQ)c^nh literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/SignHandler$1.class b/bin/LorexMC/us/utils/SignHandler$1.class new file mode 100644 index 0000000000000000000000000000000000000000..9315a33ff7393dd852304a2dbb76fca4fb05aad9 GIT binary patch literal 1887 zcmah}+fo}x5Iuv0)`+#O2tyFT1Y^ZWGWMF-xynfZ;fox}b}T~@^0bnsq&3Sf-V2Fe z^B4Y%R9Q*LL#q6mUrJRfXI8RV42Z3o?Vg#Q?lV1o`k(*)`WwJ4{HS3>V6NtR@|SwW z2z?_AEZa94R>!$-I&E8e`DG1Bfy=JfF`D7_wiOtDt1H_f_l&h@;YsK?X494esi155 z`5VgRFrQ_C^qy(wcWv{9^aN&T{MNg40xNi7JdXBgc}`jS1XSsoPKQB?Lw)BJ_P!|( z>rog_?pbc=3tWr`YT9mV+gMZoMqmb#=3~k{S{Il;!S;<;o-+f>bp$5kmbJn18*jGd zNJgIcsrJm=GYy+}FdBhpIUQQ0Zd;BOd@b<0F!WO8c!a|V8hS3CjJS&HODrT4U7YgvWI-ZVW+%?FD~Re%EX!?Uu?)F-^qN#hy} z4c7%`nSc{1pyLLX1`KbAfAj?Nrid*CO2CEuY1g2tmW2K~H4Hf2zXd^=Lg$ea|+dkvc zxPyBd?h0fM*wKfe<36fHDW8X?%_p5a2BpGu6W{8nq0UC(OQ(Ineu1lnc<|H8_bef` zw(I8Zpp?=LH}qQauB94VCe{(JE2ylNwJ?*rxAGU&Hr&w_!CKV?LYhK~^wNk|o&uwM<5_6v$*1 zMnq0f>jR8HMa&AeS3ZZu!E&EG=??P^ZDIL!-xVS3WXaOP0^7@mTbG+Ur}+R zYsn5zBgs(cSvQv9Qf{2tJ??}I89$QJvR%%wN>m-gj{1EO8iCX0?T9#xgSc@13EO2z z2E@ux9){bl=k#M~0%Rn=HHG8>!^D;Ot=SBHAv**}?FlKueTL2IFC;%atF=hF;k9`d z3FLK*p}>%+)>@-rDCtNeqoPS2qsTJkRR^chwaxvDkNHZb=U8sb@`cJji^;GnsLz`D z&plH2*`^oy4nGuXX@#M6Z>dok^kXTx-*BxU;6WM-43)pg72(%6VVg!s(EldLk03=+ zQB4+mnu|Q6GX|aPIAxd6Vtl^-gj{`nfMR`PfQd)C(lAA~ge2KpvUjwYd*twdX{s!L gJVO~XlmYozhQ*N*(&)@mreO~AAG1&f$_2QNmLasU7T literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/SignHandler.class b/bin/LorexMC/us/utils/SignHandler.class new file mode 100644 index 0000000000000000000000000000000000000000..4b37c517e57f971b4d911ba81b0621a493d92351 GIT binary patch literal 5992 zcmb_giGLJl8Ga_mPO>`*AwZhtCu0o;wh>nPALvn`&mj%;oTrIVp_%8n&NJM3O(gXu(LRzgRShKhscpc#spPH$*y z&p|7a(&5t(j3;_SJ?TS->{Q4aw479^%}%B)$4Y1@OHxF~K-5fGo6P|YHEof2f2cPe z?~Pd@zV^o*{={OG722GRrR;ulAgrNOG@Ge(!qTvR0$ZBflx1RdsH3BGUAS#LUur~p zOCQ~^!YirGHxNtr+Kz^K+?9339SkYK8|inuS|rPxZO2Zn)Ucp-0_*EKH59ePqn00q zm~5a7l^P0b>pK0IiYgt`C}(U;Hkir25nK%1foiIcBrL+Ip}w|m9B8~d!==zL-GGh~ zd7Eh<07Jv1Hruhbr2BiU#7?s(Mv;|m@rW7gG!wRbX9kN>eRfjAo#SFkT#UHW9y5om z#3nm(NW-E$bX;N#sQHk)Y+Kq+trxz81*72hw8QXQop#cu?lq1RPnjt@?ojn?FV3zc zwK2m@>Yl`ilD#da6S2sqXd!v6X($;;*zts&8qzRl3>od26%?Xx-nylA=hp3hG@wz( zA`J^Yd>GFI19u@r+V)y0*EfR9=y-S2xztd`^RS;$SYlu)mT3q?l+ioQSl(9yYo%CU6#8rsy3;3 zFpz#U33fy?v9*(>z|}FgMVGb)*;LozXq5wr&(ze%y}@I$k$YI#q#MlSr6DNdv9e$ZWO_ zr_C6RudDU$cgt&dl%cvVAy1ou&Df%$oEGG&8O1Ce2ZK6Km27c~F7qoKKs&bU*rs7> zu8QX74eY>9`f8`Fgqe!7s8^BNxs|P%amwk$ZXLT=MsA-qum@eNgpPHDRGT^?!P85^ zIv!xgkpp8kAy45hMK|^t*pCM(RGN&2JG}JC#fr&Rh#rAE!f@7l0-gc6u1kbj1`eQ? zemd3&pQd=>&#*(5+6E4S6|N+ab{w~G&iCq0M*6I1noTpbR&_;IHnohF^dqiAI*o@` zV=Xr@Aicup)(1g1VIZl75>|hF(2}9Ffk8aP+SO+!w1X@YOp z(3rQ+6R=Tt3QON%;GGi1LNgkb6n&S0cjG;79>uR6w5>K`#j>z6FP@p>Q|8pPF|RNEH{(SJI|k2Ta(rMA zz4qkez)qLq@q(33WAzLih$kY}NW;=tV2WdIF9=9Ya3{F7%2Tg$m5nN=dM2`kOoKnS zTUsj3nMh5dyb`i7lWEhuPGmu)g(@n{Gw-}7QX*v_VGY{xG%cSs#ws_S;#uB_ZD?TR z)V9XsSEGF;Wtt>x+i5N<)(#)Eh5i{RtEoo)OeG zHI)QQhOw1XrKhnvSUQXj4bP#w$shEe#ok5dVV*$kG~Y=~mVsz?w|w=TM@+UH)^HkS z^2RcG^54%;*%3;pnGrOG@iRiW1xKd7(TApejT5{C*h-QFW^(0 z)oIx|d>WtO$UL0kv6y<)Eb2aeY#1tJ*-$JF1b{(BJQLm%>pO{>F3;T6^jUV)c z7fwoXll-jmb{)SZw<-vJuwfYIGz??7KuIl7$omum?H(#tWD%;!AjC^6zDYUHQIamX z_B>yNk1ugh3PPKRAI7&tI!U#dd(WLM@n!~S&)B=fJ0u$BfVFis~A)>es7S@yK9VGK^*m!_6 z97K!>)Q?BG?kKOdQq;G*{$(*emQ9#r*@QWUUobfYiO29u{EAVi#u0^hF?H?3ukjnE z&U&V!B!Zr$y1VMP>`v~gm$*uzP>rHnn4#ka191z@I<7Gmv;KkdiW2+|zgJNME2pp! rC>G3Ro0rQK%6MUY0sf$#f5e~oJDp}8=db*eZ22=suHi5Eo3Hdg)SX4a literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/SpigotUtils.class b/bin/LorexMC/us/utils/SpigotUtils.class new file mode 100644 index 0000000000000000000000000000000000000000..6819b2bab9916d265b2c107b63c4d3a19f35d36d GIT binary patch literal 2713 zcmb7ES!^3s6g@9-;@EwqX-L}A(v<*7Aa&U(DJ{0^CMMIQ*iJ(z5GKyxOzYUju}grm zuPyst_I(c!0%|KLn}iSo3BHlw8wB4-ASB@2=S)&T1j5ppd(M4#p6{J^@B8wP_dfz~ zI^OZ4O5s>5Uv$Q|MnmPXP`Tu0$3n@1o5`2@g!|!BsNZStwnJGvmkIR_?R3&5g*DB| z{&*_dHJA!VtXOltm}wp=@7m>-nxi9jDVopbiwadc;tI7J+?-q5s8HR~x?RB+%?~?4 zRAZioA9V@~EH~%$lt+i0V#*%MItmR|K5b{W+eKIOw9{7_amN%^SpSx7heBN`A1UWD z4)-~$g|V4XC9lv-ULCDg&MAdPhX>E#nuLbzf_ubz5DG_Y)S!{+wzTeu2eAlC{8+5e zIM;?6$6%>~KVKYnb9UBL8V}%Dtng#G!t#IpH;t88rBD;G!qIMpmH&~OY`aF|IC&?q zIh^Poj97g!@gA>nf_Q_*+nI>Pdc@tL(K;I(zMwBG-jg&=7H^#iPQ*5gbFD^5ob!xx zTVGc)G?J6-OdGAa9Hu~l3({ax{t$-Gx% zoAGQ7cgCX+F)y3pEC0CD7NiIhL^EJ!Z=t z8W)SVHl7Mwl|3)j7!+4cB9@G${IEG5vlA1~W}S?k4Hq-zQ72c5ji;SL$<62dNGmL! zjZ2n_ZY~okyV+r;cgz`H6*1$rD$UU<7gq%_gp5qkh(c3~_4jQ$ zTDMEn?$p=?Hl#0Sk8;Dtmezkp%1$|rJPItzE)<;HutNJ>TmIwS>0~?Vz+qQwWv7xx zS^kk@SScuo%aGx>k-QnTXzr1e?_aXhySCZ|Gw%T?Tq7e`D`i}(aUHH_db{mx+2Jj4 z45xDLjRFk6QJQL8*v&FshTST?XxQ!20fz0B(J<^znJB~VmQFV8UYRGu?w7eR>_HhD z!ycBIFzito2E!hc_BQMZX%fSplKwU98R;>r@!(Ng$H0%{=JHuX+em3k4 zY4&kH-c(pRd(=JoWH~*u#dWg7v0^b_^rM#JpJaQaoh`21r1eMKpS2Yy=9BAbeiRl^1yGNL^zdbMFSnGJe>{YS zwgYHd`#J@GpAh0-M2rwwqCk|0abgc~191y+2XPm1AMp^epLmjZmUxkPm6#wViT8*@ z#NjC{o1DUGqM106Xd~K*b;N1JnZ$Zx1F?yS5HX^Q=q7rI3y2iaPh3P?GWh{68~6Z2 z0}aCmaXBk;4`8(63O){C>>zf3%>S-7-)9I*$o;G;z^XK>TEMCrSXC3NTEeQ9v8olU zYBj5BW>qJ$sy0^D&Z^e2s?%82nXGC(tJ=V-HsLTL{BkjThAw=8?jyeakGRr&x2yP{ z%dq%&6sqU^)z|Sr8Y_oWwcngHRBQ@Y4}1>aWd9-T`RH)4yKM?L@UZH2?q8dDP2bJFw`zUHWahJpeJarFMttal2r5W`ARh_r=kSxt?_=u>Pwf&;z zd6AEcYVy>RqK@*^)1nr7>RD0qJ@ve(MV@+5)X|=LSyZE^UKLgEsnJEw_z{sK0Js= zXdlIM?1c%ugtsw8`z}7@`A^_ee1)%RzrnZoj`n-}fS+i8#xMAl_BU0nYB8bwYN2YR zZBi@M8rtJjyIMzkit11s8CU7lBPY3v{UbeeE!w;Mcrpj#f+%)`i8-&|}q P_=i5x83X^{Uzw%eX literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/UUIDFetcher.class b/bin/LorexMC/us/utils/UUIDFetcher.class new file mode 100644 index 0000000000000000000000000000000000000000..dc75a06bda57c8949e9190c69e61049019225235 GIT binary patch literal 5951 zcma)A33yc175;BB$(u|bFoX~oOdzZ#Gr)+5Ub~xMF8_Fq;Wxt#~3692f|1-ELU1F(a+PCEz_2y(}6`M3bYz zo}oiV%+gRR(4uDLiD1l3#b?4IT~_fmO%TMWu-D5 z!C*8MUp;OfBCyplb3B+znS$2T1T*pR zRKf_R)JkwiU(YUkQ%ImD867t=G}~6MER4i67MJS!;-kr^l}*#WWz&{7o{n}ikLc;B zWkllRaf|qA{(gbljqzmM+AJ`qZJLZw`(A-Fr_WZDEO)xP&0)hszqRO?kA?L4^rNBu za^I{79kMGsK4hf(?cg*-%vdzBH=2&iZ)ehFjm2sA!pQ$)1WjrxKYTcq7tl6ceMRJi z*+DNLkd9(ZKIHMUEF%1lCPIS;3PfqGiU0HitBjRI`hD zc|kNYMy(!f!isuyqFY0kz|7(X+b3JGjgT|(E6Hj`BkaK|5Y})(eyhs-ol$E{#|~U5 ztux}Z&egWHeXC^OP93|@!-R>Y4U(P7&GeHNl1q6zl72Xgb7?4d?m{fuIzORjT*A@}j58$YuLVS*S`uJ#NL@HN1^i zZP9jC0v+$bI|-BA6WCAz=IKta09<2; z$TZt0DrO9iyM|Q8)ls&s`(bQBNk zn8G7;ERS^^wq&!jFkjCq?08r8v;T49d)yaIr4sR2RNj25$&^BVpyP-55!qA}vO7&kX^T|M zcY39{Ykxn+Yrc*);EjnYJ#+5A^i!d6Otlm#FW`#uMs#I*LE)_!IujdyqFWqo(@VrsADk za!9f4uR8vQzcZySlU=@Sw_d6+Isx?HIXvaYznJQ)iiu!4e zbC46ub2z0_m>}aV(^ew8iPF-RS1qbVjV4_A)~8TXbx|wpuxBJ~j^`z4mg!_qS>LU4 zT;`1M2wfBP`5sSRrE-5)c4Wjz>tcqO$@pEKmPOAeGsX!=*|v~}h`hR(EgG02%-5Y} z#*(j)_z0<%w7TN5EVB0Qkm?$BF;_InDwee(rhISAXL)^5x$|}5lXB-#Zp4V5CRmC* zL&rU$SrUyV(E&pR3z&TsC6gf1O9j^yEGsxOq=_X0ONvwrvsWLDCOXrj*>UDnp%HeA zWh~gvYO7S;s;YQv!bpx8oAdBGaf+?MYSOPE+7fmn>Eq&)y$KK2D-laBS+Ag}rB8IwLUn~oXV z`SvA13B`H6ua+nTMoLn{5pT~Z>AXp&Ki-}DNG z*b!90!*3lk3g0vNVB!OgYYp=0#Q8?GZ!W+1fZ|v-KeUx+?Ue;MgR^@mzly&#f50_? z=KDFU#v-*{PR~UxkGFEvWN#y+CH&$6N6k`>b&9rU=5i#}EG(#5rqo-N(^ijY;h5sPVacHIsNX7Xwom8uYnx7=8eUCXmV@ za}t9cwZ7UMF7I&PjZHrHalD3*G@o`7*LKwT>KfjV!*wTdw8O*ko1AgI&ohZPcjy6M zy-z=mTdHx9Jozqx+fO}8MeA;Zx24%Nd?)G}@t#TCaim(bG~ab&APB|eB%xR>+C5yWFS3r|wU zGgzxaawQo+_cK1p^--S^@?()|{)=?M3Eh@$~Faa2#~^|&7oP;Wliw$=x!^&w(ekD3?I zs^L~4PSLD74MKfrFf<(1`0UZxa^t*HMCQsb+Ihu?DFGLmBC}+az$JZs{v3|&Tp3_2 zb2y&Er&i|hS^oQiq;8eU8=Jb+Pr`XArjcZukC5_{OUKkh&O-ZaR7^gSt&YlxglE4StK?aeo6%lEGp{l&>ZgQs71c z7F^voh35wS)n0cFf0)EyCh(7jf9CLSzt`>6ImMy#t$V#?-(GKH*>|J2)&9=mg-KB* z32URCsk|P>x%_XEJtRykSL|Z5Pf-G>6Pl1!QAX*YQ5OmLb7EFb%(+Mo z=BYtWEGUX^APYf{yXo`U%zy<{B30P6ZjoXbxH?a?h=o*ACl-lTN7-FuYc2O~^q=s0 z??lU#SUf2GF-I(=Bm5_FVmYmu5N(h86_lK4?+ozAde@Yw9&BxLO^B5eiCt|MC|Lt! z YdVAw^F+z!vEUpsgtDjr!A}l)p2cUo0W&i*H literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat$1.class b/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat$1.class new file mode 100644 index 0000000000000000000000000000000000000000..8ea2eacc8ba4cb663003397607479389720892c7 GIT binary patch literal 1108 zcmb_b%Wl&^6g`uexUmf>AtZ$IDAb@n5T;Uht-6UCQIsH|R$U@Z-KlFdo~it(=wE>Z zLa^Wi_$b63#}Pt!nT2QW+XyXBO;Qy(3=wra(9O)tr z#W*&N8rE&hOB2g5T~MRug?0{9D0LRAXe#mxedb{eK8^f5)d|D<`tdI44b(&LP$`j) zB+oLDVU>2QNk1D~?wUm-sX?EOC9=0kdPlnPyPGe*!r9#V2JbVeO?2pN5eVpEna+M0 z=;AiIq)`Cwl>Q#cUWqf7yCl(kF(C9k@-#3kX?99Gh~W#I@3_zKsr3G38I&xuOismO Z;ZcctT;*ED6Vfeu-BUax$*HoE_y_tQCbj?o literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.class b/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.class new file mode 100644 index 0000000000000000000000000000000000000000..7af7121806b56b3e904d548517ca0e062d9266d1 GIT binary patch literal 3345 zcmb_eTXWk)6#h1LW5-dh4Y|-lNt?8`L!uVStu`sa#7(G^l-QVoVVF^rwWCIsJkqL{ z7ybgz`~qHK28IlsVah8%is7s!*=npz(itZsuXOh8erLaP+kgN2>u&&e@l6Ut4CRXL z@Mk+E)pJ!(7^bW0cB`!kIjBwBZkk-awrqXht8GpT;PL}LLoN6IRR-fe;&Jv>nCI;fYG*(gp~I35$8ItF5alKe3}RiL86W2`DP{dh-f2eFqHc2zir)ui0bM#I^c z7BX1F?G#ixWq;~~MI=O^%vr%5hHR`!F}qX7Hw=@i2ZNcd^aF&sd1&aG;DZdPr{}{J zS36Z{P*LnhlH~J41@GY_hDt0=7oj1h$Y!YSe4^kTEK<2`JKU#?;rjXek;Bea3do?n zg`-(+!*(d`kI!6J_AFgy#~@wyQ?V9b1I~z>(1wobwHh^;!MRfICSAFq;8T3g@bI-< z8CpgL#dwk$Y9pYJVeu@_boXG$pQqDffD%sF6~h&>ZscOtbyK?4@`UVBQkgo+?Tc%N zf&L{bDLiDj)$gBJ6a_ojB?EQ4{d}*%a6gvQ*D*R%wLM4YWka^!g}AHEn&h8hBfh;v zyc2Zyh$Jj}VTZU9bck*1NlcGejp4f2FI@G(Q&H+%zGQbHzSF$rnN;%*6Li00bQ#&U zEbf#{&2_n(T%=@A&~u5NX?fS6afB3ykijsGqfqGGmyBVYBuDf;MB`-sPfX-jPB8rv zm;S)~ZzN0LP5K?D5g0>~-X`e(3VqG`Yj72B(HE@_u-<-U?pk+F7NHSYgJ>@w{W@;Y z>@dlfXq1*1gurN=&;JAVGcx&?V81|lf#q-WWZbP^X)YPD=rXOE!5m%Tq(zFqwqpk% z?dVA|^p&TF?!x0+DN>{$$Gdcd(>G*NEBlHgA;sw8fhs)v(lwm!95hnk{-=+&Zk+<6=`mY3eS2M{rWq3~!%4_u7RRPGXOE9>Sv_n7+b3eUB1;m7dyn P_!@N*$f#SUk^cS%Z61P- literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.class b/bin/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.class new file mode 100644 index 0000000000000000000000000000000000000000..0c0bcae4d7683416a34beeadc613695c737d5fc9 GIT binary patch literal 1677 zcmbtVTTc@~6#k}MmX<{kvEp46wG?%|--fb*KZ|U9uN~|H1#^D?Ukl z@X-f=2 zmW<8dbb_GcDKqT`J_pZJZtT2B;CO4=%p7cA;N_&G50;7xC*Ku87s4~AM zFx&{K^nxW$(4_%cpH?m#cD zKFXmy^ONr4>T0cCtN)QLv*&{UHD$K2grhiSVOn7B0E*nH8~AUvAsX2z<2Y;JzEkez zau6>ko+ofQ&ni1NZh26ao~eWrIA!6az@dT9?9Ik$oDs0LrI)Ccb%DEiz=MmrAEj2p zIm}u(FL3UFz5FV-jSILaPzZj{)hGWKfHc=78<%l~9V**dFI=qr{h%$(3tSj5f60r` zk>1m=lXTfo&vsmu_5>S3u{7!C1&-vZnbkvJBrTU|_W@e(@OfFZWFO7tTn8m$>y`Ik znD<-1E=@VNK24i7jle`JmhR?~-0IyfdtHZ7yd3yhLp;czU$3S)sD70P#Cs-z+5N5G zv)3zZfBxqAv3#!+Kh|BfrX$T8{z`_jt6~*C_5C20X`>39N)zrlvTt+@IrAhCVk9NJ zzj%EPqfy%OtYVt3)C!W&RnN6~Tqbi*)^)=lvtS^fK~NGHqm&jkhoj&)QvHmvPn;A` zqBL$J$0_YBfa3(UA`am&qb4~o;7AJcfinX>Q{BVVn*}4PlrwucySuc9xm_ZZFvVM3 z!ElOSCIw)OvPgZL9vjodH~G$ISg2xw8c}f-*N8C9wbx0wfE%=CtY#Q>liDqQ0Y(P`75Sg9sR_LDNHd;ZMou$^zBcMKD0e? zB5mc{rWbb3P&_ac)7Oyu?f5scDe#d6+mw;m+o&|kDa=qsb4#;93bPDW&i0hHKd8{_ z77Wi*3pwPe!CLjusWO$&aJ~q>!YaAx+wQ(#^+z zAhUk~>kK33xSO3k$Ne)rG~(k(jI2*cJjdKO%zvej0X(BKi#VNWOjEz|bQds$=h3Sn ir3LE~ak?4V6AKquybK@g8KV%ZFBibck>N!Iv-Agi9@3-$ literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.class b/bin/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.class new file mode 100644 index 0000000000000000000000000000000000000000..f434686e1362661b1fb0b85c86c3853c26b7b210 GIT binary patch literal 2345 zcma)7Yg5}s6g_JmGD19RLYvS)2mxvv!X^chP)J%ZP@v|~n9$Pa$nwT0$Py#T9oj$C zuSruvrp)vQYcrwKq$rb|@-~MTXIQT}&_B6F!#)r6ONdc7$jT?6SK;ct`jQ1NE@N`MC^m zpx7}?*IWL7Qsh9FtfLee?hwf`FIM;W?T|;Fxyowo%!nY#Im@wKJAA^>l+NrhH0QjM z(817S;2OG#)towSqpgn(w8LQN%G<8ks8))?-!_Ymkb-%Z>Fk)kE!S#OM-zH9e0r*M zOiUep=#dTw478w?f`)r`Krb1I^i6*N^~{cRaK}IgIyHR6up+%8vrWx@kNSvd9|(JB`|E5wfsWHH9j;fpdw5q{1w14`mrI%*!( zS!!=Kv!mf|BZg7iSk&Jp!IdDYOl{)TW zQdai1lyBOAhNOmv3^(h1#F|sb158T57Y5p(Co#v+BHUk}6?8noR~o)#7_4(p#z`-*8a9{TI4Jt4#{Jr{zV8idWW)HHxFtZtCj3Pc7{xC-M|Jm>AqT~YYAuD4ECvz zeHYrW=y=vXmzoekhPJW@qsbsEo@q2Mq)8+?Lz+yk(5F_U$dZV55-cV?3EK!8vmlHN zb$ag~HZuR9@zFtE&W8iT2ziR#k}GFON<}w+-?l4a-E_^eoOTlguF&LF^Y^)F$;t)X zkvGMqQMu(@u%{gKf>-q|v24qE(se$pCu9rYHZ@-pjr|rR|`=C*|8%GrH0>PG&L?C z6ZAO2z1^{6eEu3!6zYNeesqMH)a+Y4{u9ad@i)l5BG+T`CeuY}QYmDW2K}VX0Dave z5`*%R)7KDL4wLN&{bi2g5z>m>U__usj;PRN?QnKq<`2z!(uZXd~>G8 z3LQ!{QrW*T!`>jDWt0WGplFKRfC48mP6PTbm0%*KN$O0KEqqJ9q5?7HwS~O)za(%} znpU-WKL&28f!pvDg&KHRSpm&|Vd^q=T481N8Mg7PhT!y;NyumE+f}s$i$hbKPmNo{tsgQ4LSe- literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/internal/com/bruce/base/Callback.class b/bin/LorexMC/us/utils/internal/com/bruce/base/Callback.class new file mode 100644 index 0000000000000000000000000000000000000000..440e095635164e619b53312252e661f7f9dccdec GIT binary patch literal 299 zcmX^0Z`VEs1_l!b9(D#MMg~Kl{G!wfUuXT&V*S#R%$#EV%)FA+qP)Z${p9>y{iLGO z$cJ;)FnC$&O+$B;b%?#c2$(oyNwlL)!E#pKTFI=SnAo zX$x)X-la2i(iZ4$NK@G%g@%r_rF8GT_ui!g`2IU9mTVz88M?dw{`cPZ_WSRlNAG(8 zK&xD;VUb{C#7dbrb%jHjbSPuT;^~lOkC~}Zbj+|rVg6jlMGcjL+8c}sBNR81qoJOm z8_cLJSiC)!jM+N`75>J4L1ow)HhrjoS4R~V3zkM=NwYhX7&23R#!%c8)J3eQ5$`ur zG4(vNSZR;N(t=AO3&GMR&_+$W+enbzc7G&k+Mxu+L{r9y9ZH+238J59IlT4of!0u` zZ6yjB*UCgxl~$P{Sa1#rmL!L4Mt^iBtOYerc6Ax! zGpSq?SNXj+WhGpHb@-XnqoJY9ks~oX6iZH+N!vDZ4ayYb?t$119xN77~3CQDD8x!;THH1r9U6?v_r9|QEl{+__Y#bFIk6Ex(BFS=I=c)C+z+kF_qu!g8$bsp8YWyh>! zXuosOVS@2lGcw}=$30G+%%dpohP(|0ED3f9W6H8I!Y$OUV571)4SNI$4ROKRCt|4f z=}5w22oCJ->o`ES<{NlEQ-$CeI#OVl@Wj%+ETZW#$0i3o$k6)kN`nVC3g9DzNgX$< zEU0uds};}E@oe0}ttpe#QKxc-!$tDKhv(pV8lKDAp%gI2jp&#eV#Ft`WZG?i16FES zwZ*iK+f?aW8a2jawh@orZ0^m(vnun$EWaV zrgK`&ROBFND~PSLtm$F0dBV}!ZERkA2A|XLS;3}KoA+59YIjFfo!9XYK2OBG`+5cr zclLF32}%pfqixgh1;OT$o_FzcYE80J_n9}@D&A?vhjEqC|0_Daim$o)JDdf#`b#RB zFTZrqbt>8IM%r|SRV9BxHl(AI2{wkRlu4%uTFWG2F){ts_%^<);XBNYlIEFDtmAw5 zK6`)~vWdUT8jg*`OvXiXxg^Wq&fxkXeyrg~bZ1Eb`9x}T{fS_(jKYe<@q#*Xl`A~? z{2fp~)A4isf2Mk?aVjPr8 zbI5lqiG96RCKWaJ##A8HsLWKyna!%yVm(LA3Vt927W0mu@%XFpDa0$Q2dV;7@Z8Ir zMLcM^n}8Zr^Ims1@LIzsuNqfph>xO@`+-Q{1ZvNqSzYQ@*7~woeH825rz}r_!MY8# z9%s?V+blL7I|ct>Ad3M1Z=S|wQ@FBjdloygXg@}N6%K}#gbB)8fm*ENs2e~XTKJ?e zt#svLFP_Awb$qjrZv>qVwX_iCHMrJ=DUF0#$rra#TI4tm+>IM~_mnIS-GM}48b%~| z2E)NDM!TBM;QFTHxZy7JDTrJfKMGHseGjVYCS0IRS=>~6xV9mSXHMf*g06c$f4K97 zS-g}Abd%#N6mi|Fs8+M9RTi%~rq*Y*3phH~^V{PZj$-HI0)7YFz~5$Ehz@Er#OnyZ z^xcAuj>Z931#0{Ts#4FR;~ViND!2iMa1<8pF@n{&18=7FloeW0@ffZ~g@!H-LmCgy zi#%xNzsE?Fw_4$@YG{1~J7_i@NnNv1PL&ffdkFk3kyEH2oWeW1g4F+A1E+BNU~n4u zRNRk>DZH23f8Yd;Ws#l6$Flguahy4YhX=X!i&OYg7GG9+yOFhqp$8t5tI)`J3Sb$6 zoOhZK=2dyN!Ie3qXBBqh>+~_>nezd^(~^r9-@rF#Fy6^$6@i_BllYb(5|k`{Fra>a zIuNXw#xJw@-9Yd-{*=XEa|{2--TXUu^WWUfqXV-k;5ujvv!sQ>FD1~+=%QA-<8nIb z3jWTQ7sMLUX3fzzUOof7Y0uyRVO zyPHnSlC0ETRaswoLY6mYWz9WU8VH`02Ej?WXc5nAx#ZXY5AU~A&ecrJ9ZZOw44Pdu z>~0#eo!Is`s9Ifl;%649KieF9EHqdv0SVH0EBUFsNt$W)b;P<^Ld2*7h^ZZ{hR7D) IFOrtW0RR&TVE_OC literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/chat/ClickAction.class b/bin/LorexMC/us/utils/other/chat/ClickAction.class new file mode 100644 index 0000000000000000000000000000000000000000..d2b84e1c24b9245c1b0703a375492040a74ee236 GIT binary patch literal 1612 zcmb7ETTc^F5dIFmw+qy&RW6Dbl(rNWkc--at))QYwiuR@G(Oa2U0|`aX1gWw5Bxb= zG!Tu%XMdD&&S|v`(FFR?Gc#xAn{VdK?9X3c&j8FK=Rps{m{PNh_xX(6sLKu8tkmV2 zy=PdmzNgu8ref-E)4FZesvbBQ`u4R$O|EFwT{&BA958s-UuFyC;)cQyRW68>VDO2s zm7J1g2y7G!<;;3MpDrvj^sB|y)vUVNu>|xE35H3fYS{9DSv7P^+p*=kVI30N!|C!u zd1F?v>LN|40@*?_Kf0AxidmH*_UaNWy-7-4HSHw^M~%E%SXsVJcrv052turf(HR^zQZLl zd%5|(1aHgyfJ95+wA}t0>g)LgQfDur{^riop<4YPwe0(kzqf z!sv$sQ@pZihVZ`%YEgV7!H)nn)7~@d)B{b77YVzDUC7fLO+})YE1hBwwMxSvw0IzCrYQTQxZ$_7r)^eiIO0jf@-%6bJtnBvKwKDE4NF3r)MgYf3D&_ea6g35?X}Z!Wa}V zQp=$YvJhdf|wjm6E*TykqDTPvhs&=;JByLED`|x{VQ|jGTZ! W#A2s-{sZj)aXrWigcYocbL}@XrEGBk literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/chat/HoverAction.class b/bin/LorexMC/us/utils/other/chat/HoverAction.class new file mode 100644 index 0000000000000000000000000000000000000000..135bf9a919ccab493d8dd17eb3989b901b1f8fd2 GIT binary patch literal 1538 zcmb7EZBr6a6n-x6FRK!jrS`5SAi7$$!Eewfs(^mnqef2gSz-9az$%$4R!a0@~^2MiniY2B+ET>X5MaS4yH!LZtol&C6=My#*= zIdqQ^e|DsBU%uWnRqch&uPe}}{zV?j-!F(K?JM;kYU zeM{JPoNe3{_O$CKB~bW8zC=N{@+CT&&L3m;GojfqNB^UOnTz&rEK!}1IN_)C(z^9i z6yqSj6q%<&;mE>QL@y%vsSo}ZMg+n*I4t}L1X7_c}X%)x)>26 c$qD#^EOLU_FR+U&dU-Z%Qlt$}u_e~+zoQ^vga7~l literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/chat/Lang.class b/bin/LorexMC/us/utils/other/chat/Lang.class new file mode 100644 index 0000000000000000000000000000000000000000..f855d842d579d4f2cbe520c836f8ea7be5da5e20 GIT binary patch literal 5591 zcmb7I2Vfi38UCIv`6T7iU}q2+3JH+ltvGfDRuV{rLkzN$+Ky8bLpV!kSy;Lg(#c6^ z3#9`J-ID@cw54w8g3!u_l!msHw6t{530-vWMF&tuzjr6eXUBC=`N{6y~LO&4NrCFAqHNsrAV{6}zeXSb=YMfQJjy@}! zG!mR%7%`2Ur5VBu9+Pc0yzP7D>q;-wfwzh4}dJe2x-`2Kvq;LEYqawOR4c0)xs+xlsYPIs%a3j?L-qc?WWvy_d{!4&H*-n@($IVI>0v$FuMJCGHBmFBr3SQY zQa%?4t2WuO1W<{UD$YbTHJP6en~mY9!b_eInqB6Km?r% zE}T(@P6?^lj*A4UQo50_Ms0?6Dd;N2=qk2t`D7}tXMMPYB{phVnT`;PHD~6tF+JB3 zH}@MUQ;WBx$)Z?R8?jmp-3kS;1KpA)tE3M*RqVn`2zf3)oUXA-P{pO#%TlyVCv1TwrBu5l!wN2=MAAStlYQO0?;(rk`O``GB>S~ebWo^vY3kP`6j?%%#|qd={bd&4DBTuC@D zhavM|3al-XXO`jP3)hoCL%2$cvqlzAi#w5r<$MH|ioC?w!^Eb2*iY;?%khIMuExuV zeatj0Eh+o#Y3{n0F81kH<#i*bhwCquJ?|ANuEDizYiZ4jaW4^QJHCYDw`=d{c7z!7 zb$GRcSCzPY>=G5P!E4KA=otGm9k>oRsCXT2B(jODna{{ZH5W%0;PrT;f;Vs%vQuRn zU=LF9CcK%-$Pj^zZqJ>q&t0R%5qAX?ha~22Rq-~Px8zw|_GdZx4i)c|ZPy!1nK_Q! zj9V1EyVNCZI`@xe&Hb`ztGE@n(LXI7@5^U0tk;~*LR#*2s=SzqWcs86I-k#ySyj@m z#DBSiGAT2&D8f>Je$DK5&L&gJ1I?4Tu`wc3+(VX@wq5Ds_N|P40Tz$vn1@s$*E+f`6KwKf(d~QE@8U`72ExI>%I;9dfP+O3L~;Xm9?t)817_O z(sDiBeGxNrP~hT|@I;n*x!Z+udUl+ro|3Jya{BiPd`iJ51y-M&go;n&F0zvQlGGxw zimhT^QQA3#&nUQujbq-$Dn5$>3zRKuQ{DW!?exrzeFRe~?!|rdcU+#pcCyc{cC%{^ zf)^9#!{g`$tNA4Db~3WfdR7 zhh?E3Rq+*kmDZV-`9mz%@YnE&g0J&%#1mR5VVa4Q9^!4d$oy{-I%%f!!?3jz^P(+aW z>=XQU`|Z&m<>ucaJ>bNJI?oF+&5{R(U~k^Al4*S)nM-od-f9@8ReEb)=JIb^CXAIV zlS+P3P>EXkhRM5HDDZLA&-)4l_{&!`KEKF*Uc_e~PC+$CYB3F<5i)B%(EeN^b!@ z1@zVo$PX^)E#Re5(JguoV`%U&F6aLhgN>6IE+BRYiAkgYJs|tAKt*Dy7@+i))mDm&Hz*`18yhmTSKj?V~ zE%N#86Ik6XpM3UH(~+L0qwqC%PheqF^BwRtH5c%%rXzPVXbpE_l3_;hAb(}TB*wj1 z!p}2_^$ILyGS47X=Mt>-geuJY^9k5R1Z;>`4Rwg~&3g=udu^)bc*A_E1w8AK;i56ZFNoyOv&DgWD}XavT5vz)cVb>5cLWd6MgYt4 z1$>c`etfBHwTI7=xyxwv!6 zn@};Lv7+waA$+HyfFG`nHXcQQcR!hc!mxfW)jO%JVem5D9$ZL%N9baw%S;fzz%M!P zXDuGVuc%%^uA<^uEK%^NM4WTKE*suY!xGBV8Psp4gJMA4O%Fk7nt-Qq+O`8?7el+4 ziMYfC;_3LEZP$xai{aG}#@{p03fqH4sCW*wcD^GQI8LyO7Nfs}SBdOm2K=Wf{Ph7m zDYN>o0-l}?>rO1-*ASA54y=nwndkVlfR>)e3smH1?Tu(H(`i@vf%n z*p@LW@H-1Hb~CmC>fb{e47y^hE!y(3q?{Diz$YrpF)o03PJZQQgM6d#2yZdIPP!rE zt0rk0Y|;?l#wk%X9i7wNE^|dzE&S9hf2u`5P&X=t%BKpkP{^JOv4|g(6Q=YRwO*?AZtJ!6Qt!4^m$WF>s#UA?{tNsA{sZxS&&+OSFPTm7%U)*R^PKnkJm>6N z|9$NSfG+$?L5)D$plRtBhx($~Of+j7$xPI=6S@_RB{Vxas$aAf1O#@abvv3e(t6C& zX6$H2w-(4|Vb9e5sncE2KC#^zq=0u zcEZRAv=3H`p_?4aNO(pn+p@%w;py{w%qB-dSdTjtvu>y3<`v_cznc|P7*B(#BXIg-~3l_kj5=dN+GbvzYQub9S@&d z^{N$Qgfh-Pk`fcL-w(&Zs!ctlcQV`&}7f zVx44SJtYbJ@Zw}mHHkcAMYpecAnpm~W_drdQ`YiSn4X@OP-D*KVf z`v~GH9tM^5h*uum)vKJDz_j#QOi~^xh5=h6R^~m9}rD0~4FbEi4uD5`$!u9yx@-8Z@Wd3CqmRCfI60h0Rute5NS;BGAC> zVJ1x?=>tV&l^nr8R8woGn2+HD3f?c!;?dm#go?|!!gHdf$b}Xn+ohDdY8k>4cv8U! z1v-5PP?9OJUB79iG@Gk}DDOKTs zQb-hOk}L>|w)640NvBqU%l`5$t@85i8+Qd3TEQeK_~c3yS-RmU@-z61f=^dbWRKgd z$e&%I5POzU;hx6lS%|+NFuj7pdDpIMyz-3A%3FTkVilVJ-XoeHA~z4+$eda#jt)870rXjz%hIo2Ru4916qzM8!+Y zMj}Rxl#w@pZAHu%GgB#|(kPv%`F(^;bYelO{TBR8#mo4)!1xMQ+(LVi60k=+@$FuM zsO%C&Hf@<&Jf>x2WUr}Mgc`yxa6`c_N%cGw(<^UdDt?96Ng?RmJDg^TIhoWh=@y+6 zHibLRd3U5cn_*vyI=^?X!5jFkg5L<->A@_rQSm#xN&1q|GADH_Wn?mRmngZV=Bas- z>+lCo8bN#%GO<;o;p~z>t zY5ZMaqfg+3Ibvq5nBH&jl|IN#w2Q?H_fQD6^rr-{fj-rto?aFDb{}f!6QD%aHC#jJ zW%^iyMtTj=JD`$bBi71K(hRquiM}y}>OveQOSY|#bXGuUBFkop(CS#Z2xL#s*AWI| z-R@%bxLCnR=OS7vz_p-({xV>P9JpWsE=ZAWB$yyytzEb%y|deOkwt8Ni9R^7aqu85 zUW%&@?RW=0BZ|Q`dgas{D)J?V?WF*B`})C9;c}=PI$nn;g=$*{YNwl_UEomItFx3X zE@W#YhuzoFHPM;Fz8%+aFoy@uM3!)!`fWuE#lvy7IjaikYQ-`16DB9}LE44efX=Y) zE}qzP7^vWI$1)BN;RHcEK~Tdk)KdgqPusM2P8_Jau`f`2_(e3|RkvyHP-F*TpSfBq zHmwglfAc@m`C8e0>kyz7JE=i-;SPFl!){Ly?S&xPaT2F!pJv*Dcdo%{8Bonl?py^z z!3czWC0v0~jJaNU0$jv+4iih6bGoBznE<&@xT(%nhT2>K>i#NF592+qSN(3wt>xlw zT*P~Gh?N)hAO&~GgSoblkF}V=taLBohiQ~!_7G<8GMIBNX3`HcRgT$Dm=7+4X}Xy6 zewgno$9#w|2baOjxR|ydX0{yjBw?Of2J?c8c@dY~8V$HLYUUcz@IAVS$8-2lIqVpf zW!wYXTqsjBp2A0EnLc)lb3I9OeNJMpWUlE9k5m1gew&m|G0FqRdF#L z7Tm=Jee5LXe_E=r3zVx1o;>7z=O}WxMi_#QNqM>Ml9}c_h#X!m#d?&m9`ksU$6|!M zTE9&QOvn2daeax9H%mh9d=rg3I$y=FYw#=@n4W*1XXk&D?|-E4yrsj@8zjtSlI|;X zx_BJh>DC;@lh}u=(gmk6_ZP~#A8*UD-cBq2g1?d*%+-exxJl*?SFe{`{WstyS-OuD Wyuk!69|rOd^LE^J{~(ka{PTbP*co~N literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/chat/Trans.class b/bin/LorexMC/us/utils/other/chat/Trans.class new file mode 100644 index 0000000000000000000000000000000000000000..cecb6dffe896c29391caab52f72fa6d687d6f849 GIT binary patch literal 5744 zcmbVP`(qPT7XEJAWN4U{7NM>pD-?k=MIy*jHHbiMrPxxXrKQCcCdsrNn#^=3lZvnP z{eHjS4}80;uDTkkD7!!JKePYAy64=Prqd>wB>pm)%-s8(@0{;E?)>L}KVJl}2meyg zAh3DRvh}k=z43f5o_CB)E^aw9x*bo=Xij|8*36uOCV{A_JMpYx>M2{Ba^gANo~K3g zyH53-I<_a?ON)o}Tuz(T1;YCb({T0+G)B9|1e$uSw7v?>0#LA8pzVw{uf;Q(IUOHP zp3zfI1dV7>5kf1Oi4HEk9&v2LoKBqdJ#u#>7OM+CeL&WyUny z;Q!vkCTGUT32Ygx>Suze=cGx7Dxo2uSduTHT~daVK+BYEWd|HRJK|`mS%JPN*_@6i z^Ru&t6F1Cx-E=Jb?s#!YqN@g05nPTd6l@T z?@a0;0=w#VPGCHGvhH2AgoH|rNl`P{UB3b96|zSRX>+noDLBA^l?B1wf#coBdDtV+ zoZ+rEO7e0iIILoT>$^oh?e`iErFu?x4p|v0r)|;6TKKbxAr(h4Os#ZUcVux|X=BRJ zZGo$6s%39Eb%NV5qTrZ7`%*F=vaF1*nOusa0v*h%PxDq$pGT1{^J8q?pp3D(+w#VM9I=Q0et?Gp*Z{_ByXfsyNLn zn)8cKU5sOznYKv3F-)mQOAMN!^oY6?VQ?Rr)twpJ%1_VmsxvBPcvTBep5hyURkXO* z%2=dDV%ZqsNXQp84i5`|Q7|X4&NqsR7%FT~1~-{nmda}#iM}L}*YYCB<1PjB0^Nb3 z?KAUP#_hN4tmd%lX9W)WH7fSdI&fry+@m6cdj%$|G@IoV>db{u%8ho1e_$2^Mad!+ zq5Po1emWXBo_cxJ!IWcIW}-BpwG^jbg_{S26Dc+6rNey(+T?k>iD)jGqdP-ltSRGrt zs_|Du&O`l<{x)C@T_g0%*9caljqX%;DcZ4?{yju6tscw(!7#iM>)ufYqLu8ekr12Q zWgY~7ZeN0R5>~-_;?{s>{y6ktq-dY_sbSWgxbBn{Omj?0j>qdjZ=ExOyeP1_{7~X;IOgW?X|^1i?^jpLzJ8 z3fTQ`h?P)RR)E?oBg0TV<)E%B1GS|B)IMS%NU^Qh??F9D%)`X4vwPx((8aw?jr%`G z`(>exyN6;s3b=0k(MGXxebc$${u^VujWQqBqKWRelebY4X*)$aChfVRb{3=1iJNeM z?6i{ww%mY&w2xx-8>LWKflzP=LSE5A>w1fV`(j0k7jW~+SnaIfAj{8T?=KH^OBtx$ zRiKXGRsv)N`^f{=xiwb6;D!a1Lb85e(@>?P-Ve3-4pc(h^?Cndc*f-wJFikTqH zeHAcId6=hzFtt+51B7|70%pp?Ob21=rI>w$*M}a zaZeWTOeyv#RqSzz?UqDG5xWB~;6=jZGI)trHPAf`zw%aIWh<|fm3InwztqYE?Vqe@ zRL)z_nv#s zclP(%-*?Wu`R~^+1K5neC@2z$_81xcSZ`Z2myPDkcp@7$%yB&vjTybC^*)WCOL4g(X z$nDccD4I^_rk)Wf(HyN=>gutSN!y}5@vPa*<^K3sN;7jAU0~;|aS2B9iII6p_QedNs zMkx@mm#BA4H(ddN_W1~Lr_M+{_o>*5`x%rt>94WM1S)H4J_b0)k~Eg^KGOTn%g zEy7+?(T(?TUVk{JC9>UPDfXQuSH$+M}WueF7mF_C%c0v!LJ9Vn=$lv{SV~`p{#y8P&rgIuv#j^Jce<`DrTgQ?>QvU>QLM= ztat7><(~N3}#wmmys1?GiKD=CO^4M{q(OAZ60N52^UDv|>U3zP;VMJN9+$-7~PO zOUgW<;v@K|q;opWcnLJz7QW+qa}ZAnY;Jf5|D^J#rSgx@(&i8@(iT{9el*bGqdX_T?*vh=T4&t|nTUB=|IDn4gtW=~JMocO$oFIW>hIT6J3 zJjhpe>4|g*FXE(vFOl|Am6q0G<1X#9*0p6*)MVL4hm6eVfV}jmIE63s0FG(txTz)L zkLsPdM1pCYk-Qr^%BY?efNWVWsrZ^C#RAs&gL)K1MlzzX(5T?&0#!Grl7h>OwUJ``CAqAd zr9kd~(tc(iB?8aXgQ8&%JjT>r^F0GI}b=|^PrDb~)w5vcb%ZqOH*%Sn-WiuS zg^Epl<>j8>X;L;HPNm zU6)5|lP}_{&!giMD*3s45_|YHUa`Ob^mbC*I&Ys;qyr5k)6a*{=bMv&*QN? z9uGg6$H(&c#1x(>f+O~snPSgTOzxKsd3ICk@$-<2;V;@4lX$@k7XFF_I-U2XzyyXO z0XOqa{)j)1uQn+WKw({5KHgu68*%YD~S$e2%8@x}+ROm+&J}O^#%1Dz-*H#%0#PY1$*}!cQAo@e{5p)H2K(<($-o zpK&f=)yiWCUdMA#tRi?;!4=kpf?v2rQ;p!Pl^NBu;f5O4Ldt5uO)7=`~(*nl|(5yX-%Mz5@G{32c%iv-?g{AQF)53r2z#`+^Sp$|8Qb z&^iU#Or^ZVtT!gmGR+xoy#^BHoDDIXz?G4JLxW%0^zw^y5nseVi8o~(`>giWY1R2Y z8a=?1WRUG@2pjPbLqE(k4svu52iTr;2K+GFOOidp#0Z{3jCbKtJkOOEc~O(C?hubQ zy6z^NBPZb;ISJ>;NjOJ#!b|W1e$SnL>b6^AfEFyXQXeFGqm}vqwXU*Kuiy{VB72v; z^N-vq8|Twdu2c2gl&>oAp=1spR?VPI6{mldoRQd#-8ch6Ungan{l|40p!1HUz{CfyOnXn03v9XF9e(tYEl# zvshG{h;EsB(I^UZ+^pp-JYw3WcU~Zo-1&N^CbdLxqmG-)=mkByZm4QF zc2RMDIy2_F`o^LxRvZTqC+!!fW*3(4&M(YOOkch`Ha9o6EYm$G)9n?Q{Fmw0;9t^t z?v32lJRCy^hb5{b0-6R8@?2;wr<={OoCiIJS)O{*^MOs00$UIAw7Hq-1v zW%o8wFIf)Ia~KiE-`%he_$BdN!j_~7%t*+1eXN5)F4!d#~sV!kmPh@vtGdj!5jI4w;?m( z-Q8}s%Iv~LRWgAiyA&-bD?2wB)&f1dn3J@6OJ6lC4n*C}aX5vIPfEH)p{ugxf-94{ z5yLzdBUsqJbZX%Htq{j7K9-mAnv|~p&8@3!p|V$g0G!u96u~RP^44`S(y*=<*X77o zS8hVWxEseU+?D}#DXj|Zsddd$?mnWuJl~M+9}rK``aR`3bnqGD3bfE$ zD>^Cl`F7~S9`1NT#S==Bk?NG+c0Q%wYkaG5ZKU79AJF|2J=Lx|7@||TPWz^1*NtV@ zjdGAGAdPa65`qMOCmakvfd){LB}jyzEF@Ow26r>YO1s(JV<&IPcSRj&cP%z5Y~ zVrljlsh2zX3yLAVhEyjvbCrJ?BMjfn3}iR^r1S=)3@cmF%zuX?c%OGj;5?%*m%Q=ZDdXmz#>Srm<5RS(8oJxGM zGGdfA67<7#|F@{uHv4~p_y+Z%O}3eslC^$;PPq*5_XKl~(E1oHa`O`5$I_556TVG? z>O`eYqQWNi0tacDqD@NK9N}(=yP;=T+LYRtXsJ|%WS{uF-a$9zizMR`xxGSeCpasv zGVLk${4~-`Y>+9P!5mp%z*$a(QC#PnWomCyy2a-m+{Oylpu@!~KBx2r419&0qSBu_ z56e_OCdh zF|^P~>!Abd+>Yl7+&-}B|g3BTA^=+fwXZy zMxNtvcWiZI`A+faRH)rUH3=Qz24tRc#RE?n$S@Sn_(yKp+?`l&hi76G7|1e|BdbQ$ zF#r6o%x|P;4TO^1mS6bL77W>a>B``MAziJVFl4&kSmcq$rimQ#3|oEailfjO3UwU6 zDE7S(w@)~s5JFQi#djv|;{ii1Dfif8s8lZ_)Os|9 zsge#?pXad|o~>Ic!?rI*o;$t(v$q&9=22%Mg~Xz}#PGyK5haHFzzfw#ypozfC8C*T zZNk>JZUEIZkQ0{&p&sJ&GG1(1V(I?66&)m*E^(R|WcFNFsIJX@U-$-^46W5>n^eJ2 zoOk;C7vUlGAdM6@V9;+)(}{iv?N{k!kz^z{>fd30BPE4vv}YsZdu)+z#ttZ8n@$u0 zCEE4l*W{hn9?cob4O%nY{z~UXj1LjUPVARpXw01`Ev-EwEmb%q+{X!Si@Y`NX1(zX hl_sqjc9(&PTu~@p(bGuVLp72$)Jf_J85(FI_ZPZ&Nf`hD literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/command/CommandWrapper.class b/bin/LorexMC/us/utils/other/command/CommandWrapper.class new file mode 100644 index 0000000000000000000000000000000000000000..65ce03f36520179c3f4f65291db1ddd38fcdf971 GIT binary patch literal 5357 zcmc&%`Bxj)75<)(7!U&{!p0Wyf?bS3LYCt=NsEXRfsIXAVjy@++jI~U7+XlnXq1{P zP17w-*K}{(Eln49aa|{MFvP8!_J`)2p40!Rr}TR>qZL7A_lKHe&6}C`?!Di4zjyDO zfBgIXI{=R00|g#|$XMFcFO3gHbJ=LlGLqS7+FH=fXd=D1sHNtjL(cV#sbw;{slY4H zdO>?$izc*0xFu(CQ#SYd%6(<+f+2dFR*3INa+)~ z#aZ1XQAq+0jHMG=^0a0e^4@*uwH6FA7OfGsn^9tJFSoXo$y;npr`+@lJljJyH%jod zo|@Cm*d{Y#4x6@UrY+M*&BvZz|ETx8pSX9c*n>_1e}?m{nXEQX$m6y6FACH3u~81C zn|&%if-ZsPMa@bqlAGPqST{kI$6i&Zy)`By?>**6H+mEt5IA^u>Q!++c2d7t zI~7Ft-$NEq++8lPbCcPacQbre&;+^-Z~Ta|e*aU_Mq0v*#cb^k2XlnlLDP3sd0B(zNb2sL%}3j-FTLQ>9UsV zR5k^N6tH=;6xnpr_e#wvD64NpGsP}@PyI~6If3oAxe^D1IU~sq;m2778u4*_Qo$z# zww9nCTF{ucWZG2m3_e9k9*a+nJ`RSu4+CRz(7Htb6i!lHwpzTD_g) zNnTv* z%dM4m){))(MlOjt)`SUsTE!*MTa)Y+n5(>3`^YxpKBwPT@p%QGV|^*w$-hctNRg$=xZM=WzWADo%MxQVxA-aD zTr^mN(kY4P%PPKtuky`;mMy+v(W{2(ycFQqReVFr%zI)geoh+yriyRLq%_dDedK7s zcX$-*j8GZf_@0XIOV_fx9MiK2)5yqks6_RqiYxdb>jiyJ*Z_EbJ1Uh0WGV+%&Z%>i8OdFZXlSsb~Ak%6IvOwwKu* zxd}7)gNhq?hZ#(yQ$Br6Z)_rKMC60le&AXKPb%zs3WPAZVn~2EVH5D4*NJ|SKdQ6 z``+uyH+b1nHFt{#)<48v9uex`fe#8t0r}y=YZE^-Jy224aWh&tcAjiOE8m>uy@ywS z=oan^h2O*0cX(HacK){T3T%OwGaGRqw)3vtnT;I?@{a3VFC84K^x!;^BOwpN{FPq* z#+d4PjRn1Tyl|%*G4vv2hZsW`eKwF7B3vV3#t`L7uWji8 z9A>}|@@XSHfq!9_!mTCbIf#oK_8ykF#IVgZFd6??zN;XD z5|H)5`VZZy^)9+02f0shb{~jWU@b56=f0&UE z;sKoC-3Wt}=%;L!CJX2%3+N{c=qC&4CtdVA$;Bwf2y2jucSaHVlZ@1pXGZ|etntDu zIg)HW0&i2>noJD^s9-|DDFsssp0cCI8iTK|c%yJfNt*ewS>X1J&Fwe|keaz1x{b5v zZsGj9czPLHKwrjucm)@D31s-Q409FFd(gLv7Xk)p}3(PSjNj5nmYZ}W!>zFT5dn)-pjm9^_~UpOh*O*r78{s2YuCn772KeP)J|JbJZe%?!pXNug#t8*7F zaMwwKeiB;7&#s`2!(Xi6*P&Hhm$dpKl&?$IZBdl4!`E@@Vwh4oLE)a{?+E{nlee)F zzGm<)d655R3UZxc=#sB?av^0{M;noKe92jPzK+4W#=SzmNDS#I=gWOo!dJ%{6H_^x z_V}$;AncDeVI3}EqqlLBl3X4S7ep7WPFzuREq#)?RowF6Oo66<_Epj}$$dM8-6W=q z`{oFVc#QWWEYw9=jTU4zYLml$OOeRk>fy@0E=^smiA7mCgV4+TgWLEMud?&}ng9QS#{U42V|nTT literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/cuboid/CoordinatePair.class b/bin/LorexMC/us/utils/other/cuboid/CoordinatePair.class new file mode 100644 index 0000000000000000000000000000000000000000..b8e2ecd9b10c0516a0f0f9012caaa3b7f1d22de8 GIT binary patch literal 1733 zcmb7EOLN;~6g{6`avZsd?Z!z++Vnw#U$sn0Q@|lDaS1h(G<3oQhE-)p6RUA8D$BIP zPw9poY_fnE(gF(xHd*i!_$>^>xssD8tv6lhdtBYex#wKz@Be=P1HckK(-2XpY&fp< zY_nku`o_SsyM4p)I+km+2QA0mH5!iN?%F-mvpzR%S3^u;@{#$iX>`rrp0U+>WVJno zv8RsP-Mw!?Ro%X)5 zCTqR8qY!I2yVf|)VN%0{LVmQXjtsI2$vw;aQZOi-FBHRReQRCvoYyghJQLIRD}`vG z*c9`Oj@e`L*C`N|juhqJPf~){loOU@o=o4BWQ0Zj0c#vmZuPD8*$`7Uj1UMOL`v zDJx9+J9*@uq(=(lTy@^I5JQCfbgBFs(h6L2{yMGj5^w#?R}oy`n)2OrnUTVje$`Nu>mA1+Y z)Su&A^gzx>;v73*(x}hsDq9BT*!(D|fMpbMmt?G? zf=ybtXcc-c1t3r8d4Suv!xpAEP#^Pc1Z(t4BcUb#MMi_t^D+Y*v|*nfU4+A;AU;A` zwimejBVy5&$%VNN@70ILr`p4nxl{aEUz#Nfb(8%p^Cxi2#}rIQafm6$QtSTU36eM> znLDD)rzj5*7~DmvxRicXrg})G_=!yXkB$hg3be4sw?_u^Z#yEm_G)lrWbi$|MDu@G C8Z#~c literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/cuboid/Cuboid.class b/bin/LorexMC/us/utils/other/cuboid/Cuboid.class new file mode 100644 index 0000000000000000000000000000000000000000..b13a68caaeb1948179545d62b2792a116963d7e6 GIT binary patch literal 16941 zcmb7L31C#!)jlVg$(u|b5CfwG5{!Zf2@oVW5)ue6qj3Hx>=+7k;Kiv3PfR$Kd+) zkwkfCEV?ezJs1xqBC%-sKsX)=^+vYnR=xXOtNjY#nQ}M9;=NtXp+3|L8j}mPCgPE3 zcNJ6C&~Z%MfXZf6vbM<2&^&3%&lddn>zAL}e9Bp^4QrM%jlo(2iBL4r7U~@gXM;QW zOjXlbS2wJxUw+oA#dVEKZ8l9C9GIrqG)=K-nr729&88)hIM@PGu*m6HJ*PSnjU;M- zQVCP` zjG1jd%FCmvbc{jMK%U}|y|ziy=~#^F4kwtVTkE={S~YX@N(RkLk-uhiE-{svlt-qI z#uzk*>9C|M8ls7CcR22+*)-Rr;|M(WMJx_092;c%e3Qn|SRaj(#t9~klSaNY7MheV zjl-mIqDhBIqd*#qOe&DZcxlv|G@iyXjcbfV!_9+z9pU&YQ8iJFSZAoWEd-rH+v@Zr zdLjcLyYW!89*UIR7wQ+_DI7%q;ixRNNWx1=)^jm8os9pREFkQ6%C3ihF-LAVujv|hRqwT!|~odgfm#WXgFWK$^7 zW70b67Kuh+p57S^4Ko{LY{aCqb$@7xX?BVjM99L@Dz|K$PO-8+&|`O$9G6Cqk7DlE z^U_}XX#))y6o;>L3C4zIQi29yGZ2en7?a4wHBjq_82%=chG;X~O?bm#s2A!T$Yj-P zd~^=eR2%+4N#EdrVtp)H0*_xZAOcac6FHn`()siy_ztB-i{sscec>n^#^E#8WDo;X zbOT*z(wD`|bAfVQZ>)3uY0|sRq>EB|+ogAhNf)Q|Lan^(BJlw%5pYv!qYInM8Bj{j zG%>S~#88;75G7p?#sLE*Jf@j54$a&(0PxSNd^;$yBNE)nVYXG+eiRs;kluHQ=5EmS zOh+Vr3Vhf4aM$wCKo4SrpRS`L#d+Uk(#>KD+5LkFaih1IbQ|3cOWi0@s%4!Bqrq(f zmdgcV<9k8_bs%CzY(V>jR&n+S3~Pi%cbaq;-3_+}K{X*l^$qr|h`~1lr&JYlm@l(- zneb_<+$bJ{9T)8a8Q!_Cmc9F})ho zq*SK4G4azQbfH1}frZO*T_a?`4uc-I^Ck6aaXcQ{EJ*t4F?v$;`MXRW$Qla%2yK&} zA4u<0unD1IW?LRTLq9a=S=;G3WSaDxc!umy7aU^ly2wzt3lazCt$JuES&u{^1E(ML ztc}QxHA{ch#dV6YI|^Wkk+}F|Jls? zH*$hcp-zjZF}5ijZ(b_i|0B`f|E4=~9nh96St7}?2=vtc{&2h%xrs!SdXOKE=PW{U zE`P{x(5a?K)&ik$7D6Uxr{%O(dXgb>g42M|8rc$t`r1|KpIwFidNJTM*noGyD$#DY z+Nwl*jn!7AjE7Cgyml!uPn9wb?E;kbv3N8bw>>L_JTXl(>{sH%c!J3RK3uzMJyS(i zOq-lGtpo9HeYtvDmB$l#lEH!~d8*0N_!uopHFq)0zgRgex9X(=@DB7u)?wUfhZeJ)9aj}RJfME&P8K-& zmkxD?`&FuJa4FN#$vm;4w>R7!>b27yXP}5;mdUdjd38>Bs6Q0#@^d*KXYgFOmP1+B zLDb}VTmdbM_4i9~4l^AG*YvqSfQH|B+**?tNz!J-;$4wwsMp{+JB?9ky0*2t!ANgcIPT*mQ22%@l9fnT ziGyy5pBM8o*gv0?mZ#d5+9o3!Og@=U0kcE!0a3&*B<4vmS*gA|_eoj1NZQ8lizc6`I+nDoZk7>iO%6#%)~PF`*=cf@H2uq4RyM3@XqUX|9?$<%EoU&PzNSy&ZLlwxto{oHwg)f8Pqv0V~Na|+TQatgmSD1Vy?SwHz2A1~qCpJsp)h2(H zzl?Y+e$~NHR=dXJYt?8Z=FJMQHxWyOfIak_yq(${)n+f!mFUs@SsoS`y51O$c1yp? z4&tFsbk8_Mzo7!j?Iz#CUuRnVdHw34`6ji-9VXu?YsgW;vQVdz?A<0$=VNnu7k|s( zZ>DZ_u`5@{dM4k)_dQ%_f7r*Kc$1Y>X%@S{b%Y@dIntJ5JFtm7W_E~DY*AiG?!`{gqEv>-nil3``;;~I~DvASSgMR}lCD&Ak^*A+b9Ylf>PlUUi)gjR^ zbaJ{2(7^{+`50R$pSGHXD(b%}G5xKyP;N(k7tqn6{Ess8PfSHK>OVc^|5*n9MF!d% z{?UmEFvBh@>%l_1o$=$zsslm9Cn25ugjku(_mzZ7vd$65zFdzMAQyd<*kHUf zyeuMT+IgCvb3|NB*SnZzMJ88|(ly99MSD|?$Tixzqp5Pc4s1m~|NTrA9fj>#HvW0Z zpj`Z$Aa?}Vw0Y#PUzIrLS0#@4Rf*GmRpMY@l{nK!ISDhz0#*R^EIK^jFCs#{9({#) zn?;k=n<6Sk`8HO}LU}>y2u&$1D>!N&9i2r_(u{|x6wO&ybM`QmKTH+qIXtDyeH z0Z+gi$O#xDbef=(rO@%KC5{0y)76qI^;Boc$w2B1wbW!KC}HMgxsm}nQWIf$R87R? zRW%Vz2Bfq8;liwLBw;EQ|dtktDuB8{SecQ18_6p8~msunB-%7&^| z>eoFFQ?-7LTCMdORmERTP$~HVeg=>#g@%;@!C4?~Hcg{BRE~d@G#9#Z9FDW+xd?7? z2yRh&DZFiQ2ySr*ZgB{1k=rLlaEn|$DS}(%-U$SYG}c=L{{sXIt1i_9_X@$Y3Zhb! z4O9OtJj1lHV9Q=Qw^TZmu#|QV(*<~YfyETO+luB^i!*3$M{~Qy9W<@Mibcu6iciVG zsl1w}EO0(}bv&pJf{qjDXj-7SR6`4?iK-y{YS3~bZJ`>vglZMfN;E|d&o0HAOO=vb zN?$=OOL5>bivzV7Eox(wmX(dr<>|Ut2iDcQ)ZK8v8c<~cE9|_=0(K^}M}SQiW?ikA zRrU~7;0fZX#8Zu@7EfIUJzoZMJIS@ybZ4#U^i{l(wZ2BzUhzE99Ghw6*g$gRws8!A zzPk?G9msVrVqlSR>F|ue*wLN7Oe1|MBlRMFECSNNZ;uLsXCp!oEF_ou;R83o-NdPc z2IyGax6Xk@)zU_)qfM~5Az0XE*xEVpi|68|_&i(`<4zR+u0eGE7F|e>qwiVTNtvWcEkU&+yiu5}4gfsQGZupG!YSEf-&3WYNp0`9Z;l^a^Tupy3UA zm3{%we+EYV5`AMp$Mf_n)W%Xbh3MBP#{rKJy{2k*wxMUfj+tWTW#l~oM&KI{mOq0Y z!GBiu8KO^U0vi9NwlR1>+HdH$j@tfC>Hi4Yk|hN9)9>L`-)P)RZ?-S=J|6UB*X*Ln zh2G+MO{EBNf4-6O%8;nN2Nm0v%}8T*9(b!PDZEJv%H<&Z3V7`+aY=d=kh_BB!;=fM zb+8Ir%=ST`AJX4|k>oCar+)won?U{UpLiz(9zod$kb&iZKm)fbLgK%OCP-}iKe`*g zl4~smm&J%D@23szFuSY8$?d>TP<|?RjL?75&H8$mSxzePg=gYyPHQyb*gl`pHp0(*w z<31M*Cwj?|Wd<0vfDz09OW`Hr05r*Nwa5J(ZorwLe$qpmgN8hy& zsDXSW@yaQkj2t~ZiF*QG=}84a?^$vzR${y*WrkO>iE$$mOh@GV84>YkMkJVy$TL9X z*@GY=N(OD?Pyq zh-KJ0bU*kwMe%XBIwL?}lw*B-KRg4lJ!s8TA+i}P6Q<>tmK6JwOO;Q-1JB9wSsI@HFGO3D4Vjp4?B|4hfXvsVM5guM#LqTVk?H z-QynR9#gayEhWK&jZ!cV36>41Xl*7~3Xbe(4jGohO=Hh9+xPS0_VHXl!b`!P<-^=K z!YxmL0op{5Msh~TMdu>0wjqx?m;H1HZ0lM0j`w&xPk@CvD#o*I;p1-I5KY2geChY$(?;n0n6z(I6!=>xn%^zs32)kT{w+NIco zw`b_~S$4Yvl?4xQSc*OSKa=(;vLqbNG#E<-+{|K>b$m3gPmZAun2JL;_7wIx-#Iqj z_&PI5cMf@`6^|PSg?pEK@GJS}Y8Zq>p=7ZW23_?VnV=*}FaBhP4!wneiO8 zqK?v&oE0Z=uR8t^{v!LDD2u>1=tXL+Me<6^_HiE*V5d2E)@NxNYMui%PbJuh5x}_L z0(LooiJPw|dz!|I2L-kpZ=_?2pnMfOsaVSDJ1L;j%$+nw%DOw#jv(~LD2T1j2{a2V z5+-UtU*RlX;hbDns4b1KsX}dOvQ>WXp{#L7DbzMts9j{CHeV&dJ88C*z(wH}v~a8a zEZj7kt6VtEcW|1oFcFV2pX17#q2|H~td|_=T^_JdN?|=BUU+P;HnYl!?;50MAxD+lP76jcIaFv6t&9 zkC)IGUWSe7N%+44mQyv#q+%~}=wD===oMfWCg;joN)qs`dHgZWHL$s6-t43km3S|_ z8i!n93!Za(@N<6pfeSaPrSwVEIBO~93mh;#AX>;i8rpV;1nqA$$+@bKh9p`JQH45G zU68ectspOdf&9GEMa+2? z7ad#Z-N!qap5%!OJ%yfqd^yvNbl8zny^86g&?00wGUjVcHywDn_%yp=Er7N_Yx! zog|9lQGz&%JO_~fc(LX6;7W=wCYmaH;B4JNi$tIBnXpA-hqd{g>)t_%$>300?SWCp zxu&Yyr*^5^SIy=QD&bDpafeHg_TdQ22gaYhUXN=%Rku&)GOgE*^?I7SSJ3nsn#a>%!a4T$pb<7@Vyd&elU z@$oc^uIUophWR#xKK0wCe$P_BE7Wg0ev_G$mevrBhm9V?L#|cq?3(3+61_^+erSi} zOz*>q@SI`Z*_0BF`6(EOojYOM!BuGEfCYw2)QjiXU1ZJzf}UZ%s|gi^wB0w-*jYM< z3f_6(t%Ida7~&*N8pv6rfyjtjoFut{Sg=RsK^n-4(Lm%Jx#A$009Z;grGd1L1|p-X zU6^2^z|EK`Y9MW+fe6l(2f;+(lOwIHl4B@LKt;oPQ7xRdZO3`1XyN&|)Lt*#gxdzW`cpCA{aH|$r z=@zKeGo}8bm7`hh+C;eEh-e%=cdaF|cCVFbOeO`Z%(O88EYXS-P5x}r>i~5R68_z| zd%ll`_yM|wA4c56AusP|A3v_drLq=2$`RL5mbmORf2#U}H1Ls^mIhr7SxEjkQ(|iK zE-IXDN7SZS`}lr*rhd0%HRx3_^i5X+d^q+6#6Lim@)Q;E(=-M3WBG?k#i5xtCdgtQ z=6kVZ0hua5>P%$*Q_{w}TyW z+$wjJxEbt_8$Y?L#I0aQ&?Eds17Wi#D2JSKdx^N&6U;%Q4h>ue_5=-E#3?uV;+_H5L(NbL1oBs;zx+7%HhSyOg~1}NBE%|n zHa=Olv_Z9btSnxu4n~pzMyJldQYh+lzQ{qb$Vr`xoYc9dT?gLSX5O0l<583!?WsN$s_t3GpftK$dyg0?LRCi1{xHYSQp^17lKxLjm&F5UVs8ReZlt|3| zNXb2yl21$vdaACJoOI|FkZsuXNvi)tAew5Sp^K;Ji3phR6{qc{} z)$DJIRK0DOW|7MLf@_VRq_6SfXRPtF^fmO!S^66Iy3A76Fa#z0(m?45|NKefJ&pVM z6&$4eqHKhJB^oUU7Cx2_5SE~>6R?lb^FKsYeWax~egTVsT)3;>^6xNHcnW)3ZeTXc zSMS!6R{@s5JyRdq{2oU(U>Ka~8~L+_`E60xVSdN12VM0_)W`F?7%95!dQt1D*P)K% zpCls`&RHHhDa%W1P%g#VnjvRuobwmUXO6BzoYxiG#e)c*xXkAFlHin!zzYEb&gJ{$ z|3^Su3~!Z1+N}@p2klRjXV2=r{I|y+^`C+~_g^@*%g=4WK5DhjdTa7?>=yFg8n4~x zkb#EXLKIFX;=eFwLvVUZ_)6gPzsD4*@PX~l4hCBrl$Ox z^0^;$hFGgJ`rY5;bbRjJAkoSPley)?b@!jTz=+M0v%lf zJ<2NGSSPy$V&8jyb%%?Lv}=_c`}=NSJ(0Eo7t40t*$@!LHr{OOE$X^^DA$yhb~&eA zG&x>!913*Jx-~bL6Bx?8@4l#h*>wSJ!P{{Xh@#KHCG-nKGuibx1O^T0=$2^MKpY8) zMhu(_(G>#*5(#{W>pHFpTsXb;q8;oR7{d+vvdeXb$P}|hc|2p_e0bb6a3MrD4O|S- zq=B9gePrN+5KS3KA|Y_G|_c9suhuXEGiyAxPJpTK2a`1C~B`h^6m z{@B1>EYSa|*YGRO16P)>|39A3q&zMVUv+nDcF^#-?auoyL(4y2((G9`pDW-hGl+7; zkYIbUqxr&nWIrp-ZdRJTtTfwGX*Q?QY)$HjY(k~kmP)fxsblne3708ToV{b5IQ5$O z2EFD)3j^kG3qxkQg|wN{S{OA`vEiMcaaG%HVcbl0rB5bVGo`1rli5UcrrV6Rkdwla zBLAa`I!!slCj>^-7&DGuKBGSQZZW|B4Gdx$Lzu@f?jemLMzDlYtl|p4YQVQ)e)xo5 zM~G>!qp!I!%EUp(^3ZjatPwhBCp)k9h-);mnJ6XWZ<&+K z`8)a=;E*Bm+Z1UIOM+33-1b}C(@-)uxvFh%kxp92Um>fgm1awsRd%n?6Vgs|P8KRR z@q>yj^BduXfh<36CT?K@v$#oub0l~YPmx!7_l7C8^B%)(e2K4^u)G0D`V&uelsI2v z(IQx;RpV?$U1+LJTlcS6*?fa{`0Z^-N|Zt-(K+Sxnx~q_a~g z4c_I%Vm29* zCN&&Nq?Z1EtmFL=@IhlbMzdT~aBXQCx? zGL+iSq*<%j<&E*=;IfahXAN}2_yr6a@C!I3VA#MR z0fvC60YkuH0apwh7H~wsRRc!^92Icgz)^T)b<;o(UejdSg$7rXvXL+_i`y)< zQ(3pmR!QZS)jDj}tbB37+HSdatmaJDi$%M(*R2}P(FLcn5nWRU(Y2D3FGi>3J8R_& z<36O2*0G?W_rIm26d4VD|7Yl3DN{yFno=XRT9N{()rwR{t#VQt8uUD|O7#L$c7>51 zI8hJrNXL5`0v#>%tXeB<8F(L-2A@@_SkLm#_A?FP&PL0uJ?1QrCp&tty~XBZnw49b z4>ZI()mr^|@QS)nFt7&NyV_|lUb3py@eU{UF4zx9UKiF#!>07aF=>X!2JT~32fLtm zUoh>M_59|nT_~+5Diwz>+cCZzrc>u!?h573Y{L&IwhV!>KsuQgMzX5b#R^$a`fl zd4tXlJB|~)?E*(67K7-3kmS5cDW;QGqvg1wsmh zy$TE|a5>PFizqY_XbQ#@dMnVB998IAz^C-a0{)-qhpT};Gv{ug-^_J4Fkt394O}#H zdIKRd=WSrf%mug=A>&?*jGLomz6Qq3=eY4LL+ZjfzkYHs5uY%v6KYpZ_?)&95M$aU z@p^cu?*-o8SM*Q-EhR&(b=;DSa{Ue_Tk5~kn8>Z~Vk-O{W+LAZ@OO_S`##br={iZS zpCqM7cS$p(IZ~D(?l3@7AE}=dBSlCr27lBgsLA<{5u zgtQl71M~FsE@_dJB`uTg?P&YH53v74a|99U#h95<`ZvZnZZeLy8OLOYzjr$P^+6wL zy35cx%PnWGu}D(ElMUR+&AY-ca}&};3$8P}crYv%H#?zOP)!-{;;xTxOTJ|z+zQy= zqlI^|{xg)r|Ed@8%3qnLo|fg!l8`SO*vS0?_s+^L?3X|K=fkWS+ach~e9iw&h=v4t z+NhtXyA2|8q_bk!72 j%<0(ri|we9%cqExeCGeTdIj!_uoh(+>f+_wihuYwJ3KC@ literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.class b/bin/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.class new file mode 100644 index 0000000000000000000000000000000000000000..a688c5d6a7acac73ab79639f2d8a7c77d5c8c6c3 GIT binary patch literal 1759 zcmbVN-%}e^6#j0qArQATLc@;&#fm_(X;=dlwV^0NtI-71PzoI%*d#l!CCz3wo0{?u z^zSIoeb5;qj-AoBKJ;&LI)3+VA~@yAWbQfNJ@@YU@tw2Do40@b3E(y!MiCOYU2r|S zU0gR?O|#`YwWjI%hqh-{T4mR%n(Imx+=}HpZaweYp5?n<6q-Q%vGvq4YgYZh+$uk| zD}EGx0z=9wJ(<1R0+F9xuU6$DgB_UV*3psUn-8Te$HTJKw08wWzKi#|`Vn>0IhJQi zOS|0DF4|nrxQ+$-R-C%yuL?{g-*ul?pVW?kw(eH#7{VCUF^n;Ra5A+s0D=({B5UEbgzAe5-O)v>LrM>gsSbnYze) zZ(4Fu+!GkS(DL3%3>)}bw&5Fru}iwPv9Tdr)?e$+oj~H!0BpWzKXIRurr5o9#cs$U zZAP&vFn`{s2lZyF(QrNAu5LBt0Q1tnw__+`RNxv*IDaCT=Uj}f{87hOSf~Gz+wv;* zeMk0W;_}yGL3$7vC^-jp%WrwSdG}qff#pAM$jYVFt>$o(8HBkah;e2(rhIdUSM?y^s}X zj61-%gBW2BqZr2+<|vnN9c!52cuXRXDQw~fN|@%a74TD#A3mWM`Po){2!%dnMInVg zBMK|@IgzH&9ioUrIify=R*0gE6USYwl2?H*@MV{aUHX!KXN^;2x#mwu#3_q8Md}1` zsti~91QG3J_$4ofnKtFN%JM}Om7GE8>= zIpq|Wsn9f0X8-va?iY+b9&7uL$SIBUFOX9FO0%iVD#aHV3b>~^BfFJJ|DqC*NzN%2 zljJu=oP@#e3esf#7Madq7YisOtBM#2^6M61;0}B8Ewh*9kg>l}mJAAf$L@ttpjG3p zsH$7+a@hY0#l16Z{l(MJ1)7#G(9|D9h_8{I@4M{GQcF4`#&7sRrhoBa{%t9Xw3Zaw J#sj5y{sDrlQH%fp literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/cuboid/NamedCuboid.class b/bin/LorexMC/us/utils/other/cuboid/NamedCuboid.class new file mode 100644 index 0000000000000000000000000000000000000000..89423284a857d6f6f9781aa83769f03688983c68 GIT binary patch literal 2914 zcma)7ZBr9h6n<_X*#N7ANDwP3h}w{VDHO#L#R_Um8?hCurSvT?E3AZUnrsy9i~Z1F z(O=QdSQy)xj-UIZI(^RFB`kponc2;~ch7mAbDneVz5o3C=idM(@w0)D!br}kSsQoe zGL3qs;o9YT#&K7zTBg`2ICd$skYBe-b9!u`UE$oD%{@zn_6q$J;(S@&}G8J5rycA2p0jVd5>%VM4wRm^kGb>**O2 zgP!q(L~_=IfnkM{$-V6J`X_;R=j@8L&{!{6wfp%(S&QNn^W_Kmnk{pGvE5y@>k8=u z6bY1rN``f*6fPX#TAxa{u#Ysd7u>)Ng;;B|cR*pz zL>Ljmt>>%K4ZEmVl0K1ZryHJCw>#p}Zqq~NsL)Zj*jZ)!Ifd%s&S)i^YF#@dvUEYt z#D|y{;TBBX#V1Uw+Mr6?1qrIOSEPM(Q!psAbhWpQTNR{0Mt$2L5v+xOoX8dn7t2nC z0AtLIJ$AU$EGzkZZsId6DI^c{Y;K{b>v+@#zEn8g8t`nxE|;uY6koHg0=sp3uoKJp zR(kKgv_-*0QQD$I??^F}@0N*2Sm9R4SF4t61#Y)ihHOwqFBG4YDJ{bmh{p;8$+`bG zlnA=TdR?q5Vm<$6>to{57e$Sy>9rY|oRHUmyv_*HQxjj{UMHu|L{yeVj^&-;{k@~m zd26F+Rpn@@8~Bko%8t#P)N#Ra7aP^8Q**6S)0A$DPNP<|ZrgH%#sbP-6n_knxQ*8u zZwlFO9GM&&i1OXR*%C(~{tu!o8N zke<;D#K1ckCy0P$e6V?fiOK{U-3P3nU?()#pl22Uo6ul%#k(AZH0&h*FA*+;%eqKK zKh{Kwp-!dJ@%LU~I)vAF{}0ScY5WlRrgaP6wh-Gzk;9iCZMOO)u#LFw2|x zfFmVGSd;i8O>0(NeXO^a$c(N0p*94bYkk0)Sn{EZVJcU*%~yF%Z8&Pf zwJMHUcXv%&wW>zhteTEPLCtcY?HaZZ9){4Kv2UmqqgGZkwMLb}`yjWetuv^(j>u9B z!PS+=>reHymDLP`lFzJWxAUj4JC}X5wsndEB|6?Hxu(s)G=}cX#&&+Zu#(%(=nOMY zIzHN;E>*0W#xUx~4!u4?}Oxs+k*&>W*n|89Nn|A(E??j7q_< zEsjMp2njd1oSO{Mf2lYTkx&psH@R?kEr-EZHeG&U!W^|r-Zv@@lNRRUiB5YJ#0=(q zm}Tf|>%oEJnpFk2FwYP$Y}+^})n6VkB-=G^?(CT*H<)_6LEIHxgkEvd?NLF!!DT*Eq)!Lv%#O{8_B3{m1~CE zuxW9njgJ?nJ5;-rTArn0kmzTWmk0O=0TgL^M5MtHk!FT=MELCjeS>^*2zzO;Lg=OX zK0>bv^XJ(&uwo=Eg=24y5IICt;LDzH?7hGP0uOn^v3CLw3w%Wm$KDD&>ibRvQWH_V z=xJg=FM698){AlzqxvDnKG7LnxK8gNMZkk)(myV;e1-m*mZCMvdnm6YCx(v@OOAX& z{Jc6OTyuv3aupN|QNgGnDg08Ua4Zqu1SVUoDn&-D-sES*KZs+w7+EBH1dVdCp+ytG z6s9S|o3uzx;?0gWF;-lcl0S-R?lvzC9YdY`_!k>HvlXC$T5NG7NhB8#jIiV}ZvO=P Pe_a>u3CZe5mTm+aErx?8t)d-m+vlO|>F_y0#i z*wD7dCtAZ!kctFA1or*aYmMN5LTKUa>RA9M{6{sS~E$*4(U{6m^j_u8c7_8q~kJnC#!=C2rB~kcOHv6f`%*U}*GCUN?IN|+iCz?ve;+nOMtFT_dj*dFfBfY6?FG(nD3KkgHc&hW# znZ`?}#6XQUO5vx4v!ii(qixUSLWSxWeZ5I^THc5XBk^4^1375+_VXBUu9#q1tBS8X_I#*;FBf$u79q zvF^qN+$^-(#b2w4U9E<~YGbs;6eH$Fo%qNoBSZC20)2|or6bX-lU688I+Hy*GNMG> zzeIhPK@?#Qf zPgv8wnfgl5H5q^5(y*56I6SPS-WvDPg1us3q zy&uCbTbRlfb=_&~jbuk{d>r=^nqzUg&c|Zj$mHtHYO^UKpeQq>P`juMOvXG{X*BI- zNtQ|^M)%_(JZ#}J^I97tqK(hua|+f`X<+sZD_m7*AGfG3sKX@sgzo2Ud;yQqzzHWg zk{#8JOOJ%<7j1kAk8>faB~e&kNZD}j>{);`RhACQkJI?Fg(qovZS+M_f{m{T`_d67 zYf`?PJ7eQ(GF!sgo8qzTs0j3R8{fdwEKX@B6TidJIZt7mE7c<8JLv>t@WnP*c)zgx zmW{LGykfHKyJ5TZXU|CxKCeA_(3FuEZA{}FQxZ3ICsG+Flg-z3gVKh z9bscchwotU8+}aAK}$#pag|dH5yeKsiW+9DaSK!Qf;niF+ z)rig4d%@6eN*10MANge+8^0|<^u3G1Z&7%;QQTQdv3}Ra@8K1y+_$rT=Kyt~x)X^k z>!U9!Z8MX=B2AL$J&{fmeir-|zHi}=73%X~8gbZpb`1{`YXj*>GBcb?kNNS2QcwOup&?HpE;omZN$eZ<<1PG^`2Mfw60o3WA%=_qR?N5X zH#Ytje@FN*pXwIs<^nJnKJ$CapAX9Sz%2Edl&~OLvN_ci*38jdP*jEval0cfHy-Kh z3fo_U*Es?%es@S5{ELl$)hR+k!->h%zuEZrT!7w?cATV4{=~+A$fU)6+nJ7vxA8(H zKgHX|a}O1{htv=B6O&@}YUZ_zIm>(-lMyo@l^qcl%qv5rsu2|1>qIzFI;p!v3Ps(_ zvzCS>%Zx+}Mpz{6^u&mxIKl9L()%EDys~UnqDm=5WQb_>2AR&OrYf_QozuN5F+Lh$ za#H2C@+u$0P*vD!nW`ibbV}yI+9133g`%>v_?4d+a|nfM8~=!ZqO$R1Od1&P5VH%z z|1i^F%=H-)whGv)Uah9?nTer{zLiSnn@@8(wB79NR}E^drFexEJTrrb-eOO`WO@U$N?XuNIxlok}S@-1vB^!6iuUecsvDeQlV$_jd zj;{%HDt9Stkko^#SrQB)xyh<+r{9DPnB`D{PrGV<^h(Bsg zMa9dg81$T%50B>@D*Fe$X0Qxj*F&Eka%5JEbHm)aB@?o2)=P53++b0BtMhiRPIg{kXkx7i;yB5L(6;9lnWRoq|4v6qGph^g@b&J^+Q zvd}rKZmMjU!P=WbO)nxiN4%2T!R=nu(_5>V|JG=t)#e~VXyQ6aXrD5lkx?^0=QBD; z6bPO2P*Y$AE%h_F`W)Uj$HlLyT|pGA)6_#|cb9RTQL$i(=U>Dj=4ngN2jPS9lqhNi+Z(3M{zS*YLXM4{hFxYYqH@`xTRk)IGsBUxh zt)|@IyBP}`xzf&+Yq6eI7QK!ATM@w!N92~*yVccuJ=KjOMp|NlQg~>A8!ZwSD>#>k zeVRfGyXH{ku!!AMIVyk7T z&3Q}?p2P9p&xCKIcWU<4 z&>Y5AQ*@B2k3bQRFQ?C|u?KCO>qf6uWUFDE$No;7q_`4UUHF8?{u27}0X#_CFQ<7V zmwHJhfKPJOr&Z!><#*syVe0g$yiQM%xj<)!=+q_x2HLbr0nx8z2A@8MM;M@O6TqO#6NG%7FqH?Z~ULBd^LfR~4J8JVB2c7`b9^phkQX zX(nCc1DO$AdAGOV8J@YZ@cCm*L?#WO`6K2Lk`8Ep2nTW4^U zBu=`ixXPNwH;JidXYfKtNv*G{xUI^nE$KgDDgKqSr)J+gQLL(pHMLW-->vn{c`ZbF zfP>6`hp-YiGfHkj3vOlX+(tj%PQ`EK=Pei`s050Ax`K@}o;Gnr$=&EFV_?kSC3-A6MOE~QFD^^HyQGzn;}d1 zBIEa|W)Xky(tz@i)+hn>AT1jrhW-HGry*LI(f^QEEY(&#iQ;#$#KP-pmU*vKj3@(( z?@$y!p8;lB!FUtP&s+E-y<+j6C;MheeX;c-u3PZT(v1s~UI%ZEG*$DMy}6VVEAT%xz7aE7R$~RGj_^Mh>!*(Jf3&8o$~$#L zexu(aM^hWu>gc(HGJS}>#D|&TK0;64NuS?^ZMYlznbZUoH|wmB#M}5ON0gV5@KfsG zXH|Nano1{f5I^G+zv$un;8{L-N$Gl;;3b;66W1ukCyP`!s3Jap&O_O)LL0+*Nyx3!NlXFiM( zJf`(EwQY=XDLyNwEu^CH8&F)QR_dpX*sN;kfg<9zRn=;r?c&#mt2k$BTQy4TclZV9 zvZ8mf+@s#XD$m>SiHGfiJ_~CUtQvMSLz-nez5HG5G}bKh4bjBsKYp*2Z*)oATvtle&_nOd@O(-!=*Y#gA+R zm-4GTb(LE0N+&C_t3qn9X%tlOJ9vFAo=t!Fl;&cay)GA}Hn6OlCbOG#q{%F65+X0D l)*{{la$#gz>SyS#Z)!3IYGrw0%hdZ+I|(Uut(;Mt{ud3mMI8VD literal 0 HcmV?d00001 diff --git a/bin/LorexMC/us/utils/other/itemdb/ItemData.class b/bin/LorexMC/us/utils/other/itemdb/ItemData.class new file mode 100644 index 0000000000000000000000000000000000000000..bf580b9cf88481230b6f49267c208c715cc07956 GIT binary patch literal 4512 zcmbVP=~o-q9lfK40Wn|@h8S>+_ecV)x^e0SLNRzFVR0h|7pHMOf&s<|iHs!IPSd9Q zzVC52cS+L4ZJjn25Zc6Ud-9B6SPTTu?GlCH)r#?NlX69}8ci;Uj@9~d+zwsu3 zBlx?HfQEykImfy_Hk>Txlf{Ca$tQD#dCN)K1#598ogCrolvyx!gfui=HLsb;jG3KF zPNc6|(*+$h8U}ODTryo;Sg;Gp>0EZ!o+~m)~H|BNsaf%QUCK|MqhMImmYZnGI9EkZBlyQ>fm9nBQKB*xzoSU&C*oI~u zO&WIltW;fOAc__Z^>bE1G`MhMi98>Q#r@XGM*0M|)j%5_(x7vN%QF~@4@ID%-9SA$ z_^zP3zBncHwvF0ZYrMFawww#5(j+>Xn>I6(CM9Is>kJjV_6gfmZSr-$D;u`i> z%J^<{!g;YtU-`LLu|)ZU=oOIIJCmv>wONr{jc%h6;NI`tdjk zQV^z{XUmsNeetd6I^JKAb}kJaCpGNYNXCnj9zh4 z+Q2ksnBrM;kp#Avjrjvsf^pWs9OfzFQjw8Yj>GZ56LdEQ*V+8dyMvS$$2sGchYx zQ~tTinRHCKZn~8)a>`m_EV7!DZu?WkY{6c%Chfe<%62lF%@x!M!NS(&W3sWvhd0ix zMvzBQ2lw*mmNIB(d5~ny3{RrPWZEfCTgkMUw~|AAoX-^J?5u%n_=tu&rlH%RLEQ9z zAhGV`al^p#_^6Ag4$Cylb2YrJ$7-4Y`|vSI#*b_0s3^YW-0Bx59?ErtcQS$VIrUtM%u#cK;W7fi>`%JsmP+(Sh>Gh;cjiC;)w{_=kxD;~E9Zs8S) zyI0?ZJCC$qlVVIJ{?@>4{En)dOG{Rk3EW#X5H>r~W5*aDz#oL(9kEqS)>{0Lw&G&z zbpt<@l2&6qS2Qy$2vv`$OLE|^7+A#{Ja?JM!x=Nr$t@KXP<66&XgNC9_HK`dxnQ1k zRBnUnaA6Fb!#x9k!J9PeSovaxg(Z^86`g78j4ij*29?*0;zP1W?BSgv$X^%%-Vu4p z;B7i8R}8)z*k2EW&jz+mb6!At6Wt{=^0$2%J6>Z)0G)hB)L=8GN3oObHg_@}#xAx5 ztP8sdC6HoNAkTS_O#-=>zelR0w(>^W=0j~-M{Pm^-5zR(hdM>eL85Og^RU8Xotmi%kZlYlggHzF=Wt@5|(Q^+2D>zF!-O({MX=>~~#$O^&4vm*^UPx{% zAY@1>dyvLKQXwiSDsCsyUD%5_>+Nyu$0;13a~|<+VPbs?6S#n@1C@S*kHKC5>70*53D5^K0TwTvsH+;QS{Bug+? zVFhuKn`8U%3T&@^hqHrfBd+c}jImy-e+V%oeNIhyq-(h~mvot`+apvp-q%|Al;BCK zHV_u`V#JNZ8g_$D5{J6`412&D7Lg*AEJuJGe=>K8@6B+BZ?n@6cdRPhbC~hCoK;YC z(h8i5E4aRfeN#d!BvLHng;l&5z-Es9KG26fj&=AfKIef>(c>cZ9uG9Jiq8iyx(02k zGF>)+-6R}jM4$92y9Zy!R|wQd?c8*!!&leM{F7#CI69PQik0xS{?5QHgta?~rZ`)V z@AO*1&Jw;gp6Co+*~yO+pagStKAF@ zs}Sbi-$A4H4jLp*Sa>}dC%HyKqGt`alv5b0EBHD8FXQFtuS)oh8?V3TSM)VLO8C=; zqHZ`n?Q>PndN|!h$+K~j45bDfO?1D4aOigT+h|ObuuMNKzl?D3cK1DKDld8%5Vz1I z!NJd@njMsIbA{_rLR?}weum;b%c^&osd9xTO+~>iQAa%rG>A23wZ?V_{>%gpC@Ja@ z(nX1#OlSV%Y2fjkt(w?;hadUhss`7>Nl9D3OGVr)}Akg?4MUQ)2&`2Y-M+$~avb z!Dxbsm(J|&e2TdekjJaNT6^;BpGZpnj;1!PvRg%6>0{pMsJB7qEXswH%Zsy zPCT0_`>`n8lKf3SyoIX7|C`y}>^3Rzvu!f(&HLVW{J;PA zy*GX6*?S)VaK2C!R0uSMlWFr{Ptc#u__J0lp7AHGQ8Vq2S?1XAkiW-B7*TV$D;75u zxCCnU8v6}@+(<LK77 zp$>rsVOv8i>6bd&1U#E!iI}xn;G#xn$yVNHrDKU`8=Z^#hqC+j#Vmg+o{h#5etY{i zda=Wvw>9-scQ83@s;Iea9WOBqVkv^osS z=t{ z6|50hVmn@fMSC_TT~N`0vlOf=ONE1$hDJ0ADElSq+eZWzH3swEmgs3yu^KJX<5np# zpN~>vg9bm&re{VfWhRCN*3Tz8XLsI9+sL^Z&Lhv@wUUm50;dqlOD{kw9%E znHt||W|G--#N3*R#A36smhLG}LQ}s?Z9qdCHVOEcvv4vRmHApxFeth0kMk{Q<#$%w zeAtXj6l^J=T`ptpH{%+%qMac0b@q4eB)fIT?p(n(FFKf5Sv8prk<9-3Q6p2INLuwn zrkSXZCyilqSVb2uQ*f!kQaicjT5N|kgs_b)prZo8JmTeY(yg{RxR<`!HJVNyFosxN zvIxQg3kyXM+TM9EVy3KEG9hqUIF>MbvtvVMdY6ORYe?CUX7d50CIU-lLO zwHR$i!5(I>h(jWkwa7`+7~5$wHLR+a;z|WCBPz4r2IEF1qv7Q+2qBfu($d+==6ULx zU=Ik*S|QaUUib(izk8)BnVEBtLsXZ#4;!D(j9q8 zR@oq8vXu7~f6dwcGAd99W7Bw^M=w}v+CSyjj>6kU{?=dqOo&%0R zn}U=;y&XqU!dcp$wTj3pVEs8v&o{)lE=uNKP3#I8FWq@LLy{>U$2HQ#D+SJbP80JXFI^nRt2DeCuVJbVNR@28jeCNj zkX#$Y>omL`Z{XQPmND&aE;WU`coUCEw*GOvMec2tqqk{zyF9eqBk^ozREGXe4e!Fc z$$MF+uEs$Jkn7}*_sSPEq2PUNr*?Q_hBfMMk3~ZX%Vg72aRY8t@BxA4SZ73q~WQHet61S;cB`a9=i+N|UE1(O#N2UM|djC^K^#uLTsekCBC`9?2AW0Ffzmg?3{fbYWhExbEwVMH7aVO*4RXa|AXyV3pno zHnSVn;#(TNE$b#XxWJ$Ru_T*m_jN347 zO{a}0<52tZiCMCzO89c#bfxRfw)Yaj za@!gnx377!h-6CT2A1uU__Kni*j(pa9Aa!#>4XvYN0MXyp>#H4`iG2+>2K#R=T@)b zFZio-C^;_#E+h&54^2$XllZ%af8d|aZGKzv(?OttI-mDTfEv2-w1#J7kSeK?@1rXI zjsGh64{@8tG?ospWB)zu%LMgwF9j=ENq#8em7P$--Q)9th@;urm%XT#y^R*6KHP9VSNtg z$i+!qa2U0{+;Z_zyr?e7_nmiA^GaOAOMEvy>7nkGwhs$w=XCyE#Q74gFU2P4yeO|g zFJ+n?FR&duIHNy!F?Ldu9Q9!rARB;Q}H9)k99??66!GSu_ zoWm7IF*JeEfNK)_0&WrTh=4MMpoqrTvV0AwYp1Jb9n8*#;TiVp3r@DZ_MG%x-W;f>fXv6-l2PI*5vRWotmy6aOv(G z-amnxYie@%2({+$@f>c|eaEm&?)lVV)CD|p>b0l3XIl3jL!a)=;WLNP9Z+=7aj3cy z@Gx(>M^_GU#zzjfOF^$K$X(AVNTsf0*r2;|_}pQv>yb0BJ!_rrZ9NX}`W{Buy8aNn ztz^XQtxEl}hxr+VfaXuFdRV z4OotK+lnd*G#|6z;_oWkclUeYl@{!u)xFl~u)0ii`6j z$;fN4aE6PTO~+aVci8{<-vBoh#z_U^3Z}`p6Y$NDbLw-;N=n~x0#y}ZKC7#_sofqt z4g1Xrs9QPr`JQ1MK6(E?nYwnhNP^eYeSQ)T9_gM!_W%q1*mR!u9(*N__X0ja@_QJQ zfF^}}l*8Yg#>0;EFaC5+;=~c=PiJH3peHT_2{Jg|Za=}f$)fJyZ~1iD z?O>zb2e*)Km#{Z&;qI;ckCPzz)en?s|=6g*0@ lJZBOfia8N7kYbu8XXJCAmC1$#CP!@@w0Qf_ih?++`fujtS0qRK1# zKcWdW-=%S)G8)IRFk>}zvB}W+_c1g0{WKN2m+&kT8P=$e8rdBEV>L3`GDQpI1#~mI z=Q`iueI>_%PiMn|>=hQt_ooEhM3W*~0oruhk3SIG%6Yq&Sn84uzfe?FcwH#0Os&H(p2y6jk$Z{fndxXj(7W`?m*n%)7kF!26`evzlW7& z?K*6NqKkZeK6lU;>T<7czsTPa*O4!nar{-R`GS+ZZLOZ>6`L9xnpd=~+*H51sim&9 zu5ERzU|gfQup+@-AMT0xqP}=IS}Q2<2D(DNcyH9Nh|M)J7#N+?3mNp5V|WjVB;WU))!lo9n_zlp993Hj_ZXm@I)=+@3qU z<$v7G=hzZIr0wI5MZ%?~F+U9FlvMp{5 zcld&9ebIobCmUy#k=rhJd+)^;2jcEXu(vA^a+}nxA_}ya_1f~aPUK;lj)la5;jY&0 zi*;xD+e%hxg-$HMG)2wn1`1&~QG+EqsD^1HJJafDr(b!tfipp^6!@a;fq0a5E|^tT zejL|IO{{g|Y@DN`juS@SCfjEX)MFX-))Dpl;*`+Zq_mHQs4RikXMpQ?G-dBns|2y! zz-Wxou~INLqx`hER#@UX*T7g5>u4eiBg@%zw)E6SYif&ulThjafwrWqY)(b_hMLOR zRkd?AmYv^OSzfMaXfxo#1Rb>Y^5ffhmYX^7Nh-qx+BqGuJ}1`TJZ0}2sN5XJc|z8t zh}mdhJWh7LcnNy*+3^!uWP*s3O7 zCYYFWk`?-tL-ZBm3N`do#J~(S^if6SXAFE6pCdoiuNjRQrHAoDWmr+V5Le=A9aoXz z%qpo~17E-wsjHBGOI&bLYK5#6qE^Q>!!ipiiaW6l*BZDE*DFmktQ|c&8SD%2W!$La zE2$+cSt~g68@LHyrA(P`Gr)MtB5s)thCg#k6?LE=ZQ-Ez)y zV7EX{Q-a!KU=TwT6uI^V={v({wsN-G^7EY7i$`@l!Wd@i#*&FjFbwR&4+Kt=Ytt`| zS|e#LJb6dCR?usUI2GuQY3?96X)MwSKIo{v`J#Pq|0O z(*$U;dz`d71!GP;g`Xs|R*d_%ne>CtX6B?OMG!sR1{DsLvM*SWp++Dt4U9_vW z#~+F}Z0Ybv;(;)eK0DJmg~LVG!Wk5%AF8f2AY{81r_qMuoK}*<@#t4QNe`iY<+N%7 zPKcC5106JOk3jQpQAebYCz!#>*2(C`Xi8RDJqFY9x(D^YD_r|i?ZZbCBMjcq(G|0t;-z2q%7=@n5uPK8g8S( z7;>7-CDtzYv^H#NZSZ=$ZFSA{4T4j$6@ARKTDAOqLl&sX_SS|K4b7@$ks*s!%Vf)ceT0wN`v0WCd1Rb*5mb@<7xD?tyc@2Ye=Kn(d=2V zvTc*hGR9P{5i%q!5%!bF?0#DrqaB%M1`vt|R1TcaCTj@@Ye^ zz!AmTXASwBGLA9qZSrj~LC+hwjE2)KR~mAaQmRs1T~D|-6lWeNUohm0vW@F8taR|| zO)x(j7l&tp7P}^JTXzG@6V#+yr+i7S)8*P6*9XZVhFot3QEQu+n($>qz9KhLnqARw zFZEHXY~UCmR5{Oc{3ACr*O0Fr1+S@a?@?J5hs9;P8n$DEVa%zv$+ryob~4>w6Ny;q zwo`7E+jL>7JT}X=&M~hZ4B08SQ*M;$no!KQnfjc_b41oStJ!qXSZ$%)DgCX9Fy zZFo9qwLSj0&x+m0-a)0*M-Qf*)9?z~Q_E9;S-MECOv}ro3RCby?ekhhaMmyq8FuMD z?v|i$D{Ui37L%P6n#WRs?|)liNw$b`dCbyUU6@T;(lRZ$E*kZ1Rl7T75Yr0f5!t89 zqr-7@7$=7OKprE0E6+>i7QBQVZVH*bE%wtRYaQ}9<=pKHF`eBePa5(gl{XYw2M$kH zh$*`|_$fjT81iHJiG^Uw$vvT!oW`tkq`lHeY98+%cchFNBso|DvGntVfkDZjGRUe7ZC1;Y$=dKnLgIcH}GQkMK{Lk`J{7HFxs zPS+UDNy_SYAGJ$!5@BuS7^Fl?ISQ7}AA$uw}AFWN=s)FCPj)g#J<$eVgOS>(#!wn-*_sUEt0zTCaN3 zs~Yle`45eXXP_o;eK^ACxatHb3Hjsh9v*eft=utxw2!YlslC#RGk*M6KG5ZTO8vxU z81jyJF%zJ7Fr%YOwq(CNIG6b&QGW-al3wF#WvmPI_}2zv0Ukc5XS_u>M zs;N$`R2#2ra^C4}%+d3SqF;5cO$(oD1T@()R{92REIhDm!ifL1})==6qrqaA+hCUk7}FhMZfEcrmWwCQy;{P;#q?zdk}LTV6%qP z_;)mkge-(pYEdjpFxTv16K`kcB^SDfOsJ)rEB0W1#a=AnYKwMbam66c7{H7{oV6Pb zY+u24&u*;ZXCptGcVl%$@h7)?L!e8tYw-|xXTgt#1TJT>Y6$M_imj-Y{0ynGA?YE$)DldU=7ft^T^82xW0CU)UTaC?S+h^aYnjUo7Z1V zOHbf8YNb^!hwA(tmm#lz5bQWI`T>gbD%^~3;LjAOGMdj(IY1>Xxr(ZrLxs7itkWp? zc~sGS))rt97UC@a^&*X}AxE|+l-Foc6GF}QV#}inAXR#75 zQPpo@6|YOq6&;OoG9P~?qFH8RHBEJqEJdqn1QBI8a#qp^N~8*};8jxV#UJq+UZ;s% zj)(DA{Ec+qOhbPIZ_<=+$BoIa>*<$o;ceuTf&#pQzw_$}Quzj@?2}L_xSZ+wroIQ;bDx`5jsMt*mRKU5a(S996?#CLB}?;>9BgudcRf2 zpAW;SW7nj!lKx@1U|f$wV6f*JWQ!JOVWZ&pREO$Vzo5AvK$h~*7Oh6u8%<@UdJ~jU!=5D@~<;z&)*u?TJ zS3!x4GyQ32KVDU}lg-+d{Wzp*6U^H8`|-4@O)_hdemtsbrC`f;DCO*L!R_Tx5H zn`YLo@5fE5Hp8s7^y4a3n`PE&`f;hMm6^5k`w>tzA|HKwPCqsbNL7uaA8Q6=o+_IL zWT7e>2IO>Ao;e`3s$4iAOI2AtAa$yoIUvhaIXOAMbU;?9`lta}rAq42mA@ZFuKa{F z(etI{4%N0-yz5<#J+h|8>2jKV3HhYUS!zqj`7G=SxzOdDl#q^^LKlA%(lvG}F1#rr zJ+4A!W_hOLAEaX|bGPGsI{!wR&?X}Gg|tl{?Yy1F-@$R6gn=%)e>VXjKv%v9jeH{f z1cG$TFh@t&atUH|v_9hQWqjuQH2QdduvNam*Sl+Qh1|fWxf}6W`8prscJP7iR$MJR zd3fpPi`hN6PVQq4Ho&K^J-AUG#?A5rd`%w5b~%6@@)W);&*Bz2h}-0OzBIjpJLNUL z7`=Excpa=H8;&0WF9a!fu9 zLk?pm|4o%6v~uEs0s`TWj=K~jNHzb`D>6TN=I4Fz29_rg9z!h0rd0Fz3xYinLO#`0 zbwFvqswyF$Nyz7`GO8R$vVj4j)Pp4FA&jCgm12)6j;YoXDRF>zvL=G)C^E^{O!Ar0 z9L6YJx=jL-$fDiHxlVfZ?21Zy(}&H~`(dwE(2}>v&H&@BOvu%Yd$i7Lwlm)4)ADYp z(Ovm$xPj4bk-Z=Jm26P(vA)K!pK*{z+_cEnPhdK>ZInw-;Yz8^wi8!#4~D}bxk+Pm zpP#CIRl_11D~y{%@^#gg$Aqj}O@XU`5mu2geNb*m z?K&iPXvpf*YYOCklMqV1)TRPGCz?9gE8Xi|1$*SX&DHd?&sQs->#4qjaz#~-5qg2d3D&{d1;fD;ek2AnN$vo&ssOIC`={Ue}`eQ7`)AX@t(1M@R zBY#HkdzRk!96jtHU&nvJK>Iuc-Y;<{enoZvngQ+*dtc-$*l+mvCI0@7A@U`L#NU&S zm+>C{fcMo?6J8MwuSo%3m(lpE6yXh-z~k{0yd^W~2`US_UZJ$iP8o{2c{dG(ZArh; zWvXd1c{H8z@_o*;F?gOt4}O;hI9Z%r`F{FMHCM8N?NY8_eJy7K@&LWcL3(xi`-WgR&6Pv4m*)~&)jr#87*mxuuS9;BkSDgI zq?%p(g%5^LnF-Z1X5Z87+kuJZ_fO4lYtFOgoO+jSNPaG$dGA}KGr8->ESIA+e;(67 z`+kgPE+;Px$Zzh1QSGu@D_@x}rTL}$ZAT9EquX5fcjj8n$F4OuYprRSwX9_m^78gv z%l@n%W2-B;a6LcUuRjHR`6)Dw zYb9NPDo7jGM0rhA9>X?KIh{smEuo9NO2;XZLS8+oJTC&5yg`Vy(}iXvzfxJ7IbPo6 zcx5PCF#1FFAGkug92_(K2v1W53Vr1fW@lC_Z9|v0fGOG$nuGo5Uh;Cvh;u4Nm@{gk z0_=C>?@7R3!crZs90a$2B;-9M*Q}h5ZkIXkI8w48=ZDFoTIoZsl*a^;Ka3!tD^aZc zp&2vxwec5dP)7m+?+g6b#bZGeVQ*E{kj9Zb%QROXz>L(0yqw)BgQyxvv zI~mi&1vjzbOe(8RCZV1fp@^=qHcu1XkR-Z@xq(WjH4-_S@%Z(mLJGkEUC$&~MLf~$ zDH%})HZxjvq^Qi|qk-qFgNlVIsm>G&=^j$A{J46LmS1D59?}YU`#I(gjNzH8X!MXa zI**R+vXyAXgW5?Mvo=qqGJ{;sq)E*pR?X&rQ!K-LDaT@|z!_3aPUrAg;>LN5^NQmI z7MW>|JJK9`lN`ISN}HffB**obs!gKt+RQ_RI?q~tlhb|gu}>N5SZE*O3?&!M$wWb& WEi_H(SJS32Edk>#{}U=p{`^0nd-fUt literal 0 HcmV?d00001 diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..257aa50 --- /dev/null +++ b/bin/README.md @@ -0,0 +1,2 @@ +# Vengefull +A bruceboy skid diff --git a/bin/Vengeful.iml b/bin/Vengeful.iml new file mode 100644 index 0000000..914d662 --- /dev/null +++ b/bin/Vengeful.iml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/balances.yml b/bin/balances.yml new file mode 100644 index 0000000..18e0854 --- /dev/null +++ b/bin/balances.yml @@ -0,0 +1 @@ +balances: {} diff --git a/bin/config.yml b/bin/config.yml new file mode 100644 index 0000000..65a5faf --- /dev/null +++ b/bin/config.yml @@ -0,0 +1,87 @@ +death-signs: true +diamond-ore-notifications: true +death-lightning: true +map-number: 1 +kit-map: true +prevent-ally-damage: true +exp-multiplier: + global: 2.0 + fishing: 2.0 + smelting: 2.0 + looting-per-level: 1.5 + luck-per-level: 1.5 + fortune-per-level: 1.5 +roads: + allow-claims-besides: true +scoreboard: + sidebar: + title: "" + enabled: true + nametags: + enabled: true +combatlog: + enabled: true + despawn-delay-ticks: 600 +conquest: + point-loss-per-death: 20 + victory-points: 300 + allow-negative-points: true +warzone: + radius: 1000 +factions: + disallowed-faction-names: + - EOTW + min-name-characters: 3 + max-name-characters: 16 + max-members: 25 + max-allies: 1 +subclaims: + min-name-characters: 3 + max-name-characters: 16 +relation-colours: + wilderness: DARK_GREEN + warzone: LIGHT_PURPLE + teammate: GREEN + ally: GOLD + enemy: RED + road: GOLD +deaths-till-raidable: + maximum: 6 + millis-between-updates: 45000 + increment-between-updates: 0.1 +deathban: + base-duration-minutes: 120 + respawn-screen-seconds-before-kick: 15 +enchantment-limits: + PROTECTION_ENVIRONMENTAL: 3 + PROTECTION_FIRE: 3 + SILK_TOUCH: 1 + DURABILITY: 3 + PROTECTION_EXPLOSIONS: 3 + LOOT_BONUS_BLOCKS: 3 + PROTECTION_PROJECTILE: 3 + OXYGEN: 3 + WATER_WORKER: 1 + THORNS: 0 + DAMAGE_ALL: 3 + ARROW_KNOCKBACK: 1 + KNOCKBACK: 1 + FIRE_ASPECT: 1 + LOOT_BONUS_MOBS: 3 + LUCK: 3 + LURE: 3 +end: + open: true + exit: world,0.5,75,0.5,0,0 +eotw: + chat-symbol-prefix: "" + chat-symbol-suffix: "" + last-map-cappers: [] +potion-limits: + STRENGTH: 0 + INVISIBILITY: 0 + REGEN: 0 + WEAKNESS: 0 + INSTANT_DAMAGE: 0 + SLOWNESS: 1 + POISON: 1 diff --git a/bin/coords.txt b/bin/coords.txt new file mode 100644 index 0000000..e69de29 diff --git a/bin/enderdragon-art-old.png b/bin/enderdragon-art-old.png new file mode 100644 index 0000000000000000000000000000000000000000..e33ffd6a2e19d287758323f1acfccbd684e08fc8 GIT binary patch literal 3117 zcmY*bc{tly7yiYsO)QBrq)}_AsZzC6f~X;uRv21El@gRzOVqAoms$p~rCLQxrB#Mn zhOtc-ODv_EA|bJjT~KSq(nb2E-^}+s^Zjw}J?Gx%p67keJ@0)_s_hvIgs`+Q000O} zg1H@kC4V1+0{q$9b-RGSKtk*+Oo8fN*+ssy@2ZK72>{e)iG01ZpYIC=5}ZQ-K(yog zfOH3xT?PP=c1v>;hj6!*!Vms3-N^3b>?CRl5`}Gh0EW9zZwvbxdu&2o(jOFXRA+BmPP_V|b zIfXpWT#CswVrv~)c^VZ$7a zgO+%i1;eenf1Q=OlWAg9WPGv}{d(?1ZinDY3A$6oAS}t0x7>~+;ekCy6EyKr+~*;( zE%&T38;BGKRsEGsVj`y$onsDfY>BKYv>yRy1-MGOb{S?q5=T`HPpiW1E+!2;q${p? zBKp$ZsMzJHFG5t20>g-pd&=S6ov9KkPX>M8?OS@Nvl4i%>t`*34>E;uVycYw;b;!U z@!?7ms1)tq<#~xW25W&%*6d_^`1@yCIpTJqJ;LR#NIyy=N>tVp5m*Zit${j$0yWS? z(_?P&CRPH|^^@94gpJaI4-xv6k;B7Oj}ti+@izV2 z?KjP8LZ7e5QM#rD;B7k2`Otw>{F)^aL-02P*D9?_PB286YS5DNXn$AM0cL_-`8DK- zoBl|EP~odruXL_*h#=a6xP!0r1XZ1DQRyn4z!Ce_L#O5716EUcg@q-Q^Ge+0OfL2P z*$4UV3*O`c6fA{WApA1U9BSLIw(-RaA^1{SjEqGCBs?k}LD-jVPY*|dkpj)7tC3Ww z)We+i{&8~N?06l`91(c^JRSY2+{4fW)L$nLz-OMt(&U%pDck6#p<^p|Ll?G%+6c{V z-7K-p=(M0e38=BHm~|cK^%CKDs?NsVCK1{qffU|vfV=Q;&c?R?d5`$hgUKTg1!kU# z5~&+HWUf@7(s`uDfZSV-hoLH1Hm4T2zqwTJu~lw1W|rof=C%CZ1VcWI+@=HSj};Mu zLi01{s=I3W5Aa9{SqagQQvB&xEU>w8lr?RRA)7^}e+(TK%Lxv8VyliqoI3$KUL60& z4;a8snh5WEU7Y7R>SIyvT0qxBU>p&@h<&?405J=kcn>nBQ)D1mM>@y1#9-!LrG24x zoOUPe)x=`({;1+E2R^Kry?s5a#mbS*uo1FW+|+T_(yFPNRK?5+fw)5!ecD|%nHVl# z1kA1r=!Vl%#?oI-CI-f?VFJp67!fg}&Jw+)(lX(1^#ge3A={6_7(uZgWZ%j459Mf< z&S@xSAC<=YTFsLc?akY0s5O5$wh4yqt5%)VZ8s-9P-JN0W_$eZDd{s`~=VZ-@o6={-Q&a0G+lENrXQ`T|wh?n&Pa&55)oNUFHz2Q@7lkdG9HQPj@-RURF0=%5YWu`S^uY4X?$*LFM$ITeF&VOBF74ELy zO9(Lu8r!>H=VlA1UWnM!dl*xj>j|yuVVB1~HR3 z^a8}#W-mX<-A2}adVmN&Gy)`Y$uQl<#zz!&T~_X2ewwY~9sZWgFGM9N{OCG);(F$l ziz`YrISRVCd^zggM??$_2$KGU=0Gv0-`U`i|&%r zs+#dLy4CfoDMNY>XGr}cf3C_e3=TU5KX4sc+&XZnX#$?^B_cgQ)@zbodz7*@H?;Iy z^I#VHMM(;}F}Dz=U@Z4~Yg0liPr|rT-{nofy5mY`$V%mjT$0?<-Y>4Mpv{%2qJyRKbZP)mo+#lx|&sPw){c3_al)=ey0^8bWt zLRyT%TXX?U`;B9|08wu=QX+*a+p&Zi|0cH**NVQV^50PZl1RZ8ck0(ayC6!+-8G*> zEeE9gl3JEr!1%=qKJL7K%-9;p=~=q0l@4E8eV}}}@4idvAwDWh0$)kJzl*JW{2EF* zi>a0QOTKk5yh34JXuTrbYRe!=5=-FdN!vy2pd1wn#eIJCBjL(M-GH z=s5fO_y-XS0}4h(u^NQZ4l@g#Uz3w995ShLjC3bm8-e^{pSol-!LT)5I=X^x4zJsjx$!0 zp^Y!Mhu38?+d1BHL*zYS68`li1OX>n3X#Gn&FO0aIS~;b5VXv)9{<3jD~gk)G2C>; zIsMYJZR?}HK-=B&!)kxX$XZ49JZFJl5!B=)7&fCKJ^esd*3}6|Fx|Z~GQK)xDj(Y> zP4#sG?L_|~Kuk4Gpay@I_DALGYd0<%-j8xY zlyP@A9b}&=c_V6|kNF_)bVyT!`LQw+Jb+~HBxp|mB1fZGU;N$t17XescK>uWd-z#x z-P35T>4DzQn!mJMI>mF*k3-66;cvJewgeZhuR)+5FI4)1A~|a(?#kWonQui_X+j%$ zMm6K9Z?{pNUwG3)&6}y6jc2bhzRujPdaiJN&xS_$k#{R%n?paTbZqvE&w)=kJj{o4 z?%^oQOi=DO?E@b}#N-zXP6s{7D^G#gr`$^PWUAErjC)yME=6c#3Vm9g5q*tbHCa0% z@h=XB6Y%mP^$phC%B)YNXx!p7pU=ws7;{w0lwPOA@_dLM#o&?wQufzrE)zb6R(e*~R0G`r#x$ev1!So;qV*ZR!#KAB?!i AdH?_b literal 0 HcmV?d00001 diff --git a/bin/enderdragon-art.png b/bin/enderdragon-art.png new file mode 100644 index 0000000000000000000000000000000000000000..31c18b3ac0a3f880a585628b24e5ad99c5e717af GIT binary patch literal 3142 zcmZXWc{G%5AII-8nF(V|DaJlMRFY*ZQ6e*g>>4VBG>mnSF($m$$q+HtL>_yhq|`h} zWX~32>`RG4OtNK9^iI#)Iq&w_6H!{?- z1rz)a-(;mFN-=OG(j@dE&O)2{(KENe{Th)Alw4fUdr zD>cB8;sTHzJ+4y~ue(rDYKmyZQ!Y^|E&#ySY@~<16zH&!?d>Nxe7J3RTKXvn9G2px zZIg0z^axK#WP~?L^})!kBqvGSn92gRC^vs1Pt{wqKfoK;q+8?z($URe#~no7O{(2} zwwPS8ne(cT6fkpRdG{?gd9iAzem1Ax+3JcL@vd>y5Ikgh&bzuc;!_mPg(9 zZTm-4l*!P*z@Z#pv?Sjz&Dk&k%Wh8+r}rIbcUJLR<+IAiPg0PLf%5L2r@o^y-*ze3 zqaoD%@b9fO%-V$sBqC;y9iTyT(8I)d-nPhf2#m45W!-kU*lre~4HD_k&3 zTgaz!Q}p9OIZpj9?!k?;{S(%T>Dl$<-eEv|!&khkyW8@O3UmUnICA$S-K=*b;-)SG zq}WPRZv}`LVFu_XK315J)Ti>d@&@Q0Epz*br9M|TZ#q392^Bl9-Pox9$R1*;W^|sa zj=E<$(?PgcUQ3un$d7vkXWA=P0^nuSOGPxQJS*4|!hi4`zTs@iB{{QAu8LT!he(X) z@H%)s?~5<1rQ1X5L1 z^%B!GW{;IDsgm(#b(Jq0hFHB197ws-xYg4R$k`qX3TJ@El_AtdB#WDffmVwl_+*aL zSKyGfeL-g9>nIotcapoH40PblOE)Z2baG6Nj^%tE$bgV1L4_h?H+C`FBix4as$}PdHRo4>>sG!>uC(Mhu}M1CV7L*d<-+-M^D6HnL-Bda_R1X zf$Ud0$i@(hL?F7_3T)ztFf=4mUls|rN8^HEMBww3#gi5u4O2F_P1^1lZd7Q6H%52r(SF?f#AbvXU2OpZ-j3Cg^&3t`Ms=S4i zVy%TgpIGJ$g)2Abbx%0uN7nW_sSHpu>cY76HZ2a;egJ!8=IWP)_$C1c|AKk?hDN`?27fZ`r&ty`(CVd-5x24~X#PzXCxY^{X7{AXrS(NcA58R)~Cnn5iaUn^&grs>#dW2xB{)>smvNb z+dV{?vgs%)?OZy>4=f8kI<%h;ESF%7GQbBWRw6-wHwnat{~#hKae z+XGBG5mROJuc<|oQopK=>6)H82+6au@J&p7;dr!gW#SSYR1$aNMA{e6;V%<5>r2xw z6WgTM*Olf=tRHN9Hqq8VDtVSqYG!t9OLfj%`)T#z(1K@PU6@@?jm?DphtR+`NCGU0 z_Y|ZY4S6YU3|{QG+zzvnM#e( zy3(QCt|&F&>Uv5RNNPZ1anSmi33IRIRrs^h8;`WpL_|6nLDJb~7M(6QB+cRCaBax9 z6~mxFXI$(Zw%};U=eJi4iv1SO@3LDY`S<$@MeeJ+O(rwQJ+IdY9busbP%vVIrYQQX zj^Z#*-rFhh{}K4Qu_`aLqezNh0S}8E7%VX8YEBf5@=^?zyU|oNTe{vMcCtG>Ej#@2 zVat~bt~*}{4XkF=2N18U5p~dHHFhMV2U5f11>gc3z+!fG$@)U`^CoBCb)MaL9-s1P zQvrv>yj!N_svp0oyCwSQNnGxFkK(KKllrlE|41^FsM_$eUa(a;%YmN-QJ*AYz!Nf2 zAP2mFWN`#xKe*Xp0|BXdwGj3(CC%Znj<;yu09!bpKTp$^b=2tVTh1|)Un5zqNY;^! z9>7bt^%QW;X1Q`^%!#PPdKup%w)wPm^XAmq5~gpzHmjtJIjvP+{ciqR)Af20WSh{T zNYL2;@umAQ>ocui+-e6CM{1;Rqh6$Ex1~G43U{`7PN%*2S^3FJVQKQ|SVBqs!hAf` zYARV#vaDfJw}ctmU%+C_T4xIn`+q%f4P5T7jexKk6$p*w@2P%mqp8E=)k7m&Pb$Al zNqK11OUKD;IN1AzZBcico0;Fr->qnG!0^l3dNS6tNijZwks&U|JZHUXl_O3+V|`X%G(Cowg`8 zEzqfUmlOnRi?DbKDF>7Xmx!3vKhZfYM4ABeRC{!8RGl(Pi#aC-ZW4_9-z6H8-@hBN zEDMi=lLm4B;ZgFDGmt_sJxzUL(>p{51V}qsQc;CbeShoHx)hi(^j2w8V3J}xe#(vz z>8gJ#4qPC>LBL!t#~QKQuL0S2{~y>gfsoPQ;uuWiH1fR8?B2Zl&mHbw&Hwrt+?qzF zCSW#qxNj%g9YWzKu!0NeGVvgZxsp2NytAQ$8W8HkXB-eNu3fHw1+r~!6gO7o@Y4gr z;p|%!r(6*ZQq|}j7uR1zm8_mnG88Y)lUPD$aJH=PJl-Hs&n+vF@w(uGurmXMIuJ_4 zWa_QOgS-#+YCy`3^d^w3W530tV6KSQn(`Q>Kgf^P*urJTdp|qv6~g#9ERQzOIlc#l zqk+#X8vx!7Y4Rnnu~Qx>12Xr0VD5KfIK`U%!6{Sy_FS|EhOf|tw*^;sum4uCiMh~r zvHh|1UWjGKG@{oi_wooMCqCaFExUkKL7`5=Y@JJ>us&Eu$dR9p9}7s1R`JE78696u zuL#aK6$crGPox$sGB>2BhBZh~&T(;W zeZ5ll#Q^lhc3*t|y{_evVkUD%q0_>r+GDV;g5-I!Vo-m5DD!sn7s~~<%iCS7)RpdB zXwK-A`ohDOxj9)$rVA-H8ov9{tmvfESe8^iKmNLZe(e@-ORL-$6E_ZSe>n{P z!HHfJ|~nf)B!pm?lS<;c562(As@5r(>l1 zTy`A)n1$%p%`j|32p57Uoa;H}Lf&7gUG5}jt-E2@_+{6(b}orm|KZ93sEkA_E%G%o ziOlgzpc8;-S8mANUbb7DMOI8vpOXA+enm+$*fU^$Xz}y6#+Z^<^Y!m{a}IASb#BL1 zfWUffhd-&&K5R%5fYx9xiH8AUam;}cJ-Jo-;MVu{p@{^qN+My$({rcy)6nZUX7h^+ zvi(1%`kzAm?7}PX4-SP(1#UkSSbTTFt|oT_kqf3K`AZ5_hiXT%d_`AL=b()Tx=&0O zQRqi^9w~lJzUMS>Jk=wc*d-}Xa(Z-nB&3X#=WRfcS`yy(ucONdx|WbTi9L5kYV`(| z!kF95_iWm6q`?b(U~}fz*5g6r?BA(cx=s`FMMw9+IF0I`SWd40KU3w=iko}~qkYLT z+N*gIhkk{N!3j~l@U$CE>USn`72AFSF)-?_1wm$y$)jIs3oQxxdr)S*&FH zlEp4Mnlm*40MK!Bb@YMWW28Uo)K$Z#+SjA#C0ZWiT;Jl5m9{@2KpHkN=0n7IpPEpEA1Q3(Jct;>;A#kE*=?*7= zjsYff+^-XXr$_+f=Ff2jPG0~@tM#jzmN3K=#_eae(t#+HXU^0O*j*(`EDvwN^fs3`!{k7{30AwXj zfu6RjH==rceswircj5Te$TwG2`;C~)roNV%JfR%`yp%-O_L-v#X2vX3jS1~LJf}k? zXq8shy6&Bvv$}TYfvmRY{#`;T8>d5iik>}dX>NYH=(@vl#%=!%ecbZZrT)Dke@2sg zxjamc3tIg>1`mv`yD^LCW|Nz|C$8P? zn6|46chqRR!`}Hf=G^aRziKr9qD*PD1WvD^D6LOK9$(2){^&kWk1i>F)eQih#e%Yj zrs~QuL7QLJg!jL*?RCkT1H^FL_O1nhRgNYo+U)|{N_7Bm%!)NTZLj~nY`S@=>a4OK z>dUlx0ts6jOs3F21#WN#z)L`zq!&kh>G z&()yQMl_DNZH4ot#DzBj+@_wbB`(-~v1h$)9%`Sb79F>mxyAXg);+cao0c#&EB&76 z+)SHYghQ?O@`7}qCs3%Bn9|>-tKqMQU{Dp;9L`vqYb3F%&KRB0&a0Stdg%$};_V+; zHD|(ACdN9IY7kVy9T1G!_O5gf`r@aq#}TtkEG9hHu+mW8;$1$^DCxNSxw)4n{CRyk z6NlYKcQrSDJTYMsT5o+k^}3bG#O+kvyrMnh+|K+$yFc;1^L@ULahrKgx`pdZVgAZOGN~>+-9jCFHE~-H`9>hxcvD(Rg?u&o4J) z$y;B2UvAFAF5HCbA2M2f zpZUJX*36#jX+!#ukID@`s(+~1G5jh&yCWs@%Bq-54?%WA+%aj3pX&h%xT;UH}bD_BwbG0aB0IodTrEnwmlo4XRyp5T6|74 znY5JDkXC)L!*;`s_Xpb0TzZXO%~O0+;iRhh*LfMf=?`4E)3`G~BfZeDI)B>Av*<;$r1A2QMl(#zYA*PZGhbnrU1)&G3Q;^+C90eJDfYd5LCdbiZt zYW=()6Wn+r+KcKH%RS#}jAo$|{ZBqQec@<$Za3rIG|ESc=;tO%6WOW(*ATG!j#cS} zn-{9Qt_d<%$2C$n8uzpNqxx%s?3g)9T;=Vt_OZ*yefbpili}6fwxl}nc>z6pzuK+ff;}gG z2taBUIvo3rw#@X2nc7({=+C)&cl&MPfxOHGciZn2+^*YWb@1KK{p}OWC%)WUcyz0~ zKhl8y`tpf2#IxkJk#(9)Q+`;mb*btJ^2Hs6W}%O~^4k5A^P?}%jq(hRT~&5_Q`vc? z;I~?Snk{h~-qt^9U+G0h2Q;2%eBPR&PnoiPNB-oxX~|PIJ~ge6Xwly$xP3LXe&4yA zyz52m8qR%A+v^5o=JN3ea+6;tkLT+=dwx!*ap}4C4xwrQQj3mUC0{H7 zvu{=3U1&@Dh4!BInMUZi|KdF3$tQkohyMDKj~2f_s#{*t-AlQ3rOr>u&+`%I5%|UJ zOF_47{`TCqPY1q)t~|LobZvX3@_prAHRJJxPl_HsGPrL;^GSHT;H}H}${(-vWxNYV z>JW7N{&BG4m9fwkH?GkY zyt||)d3oQde`o8$l7-bPIxk8(&(^g}^1tYxc8at*^o`^Vxi9H~S7q_R;^q5_I3_{?It}MYL#MZ*^7iv+#KxCri9a zR=>Avw|_=`vF(xV^1k|~@9HKR8X9Aw!Af%q2uyoAkLPN(?iX~2A&=U+18B-~y zMG8T*4=5I_6R|+2FsLWSV|89E@c~ER$`J~3A2X0}_$o7Yzu@ZcVwCVW-|2|7=DRX5 zg7+Pnv}RB?FsBBGnha4VQAHp_A`sC8f)L8!bRD^fLH97}^hB8Y^Z0B*xOhGpJz6p{ zaYmwnjtmJ%kt&f`91@46VXa9PI1=hlF=iDGM)p|mE^`3OBj3>=;la)3Q#;An}j9c zt#KF}9?2wH5Rn863oMdBAc9CHi^*c)t*zLW*4P0Eo}RMuZ$di?SnH%K1`0j6xv&K+ zC_FrKNLV({3F8NDN9Bv5nF2Du%Z;c-N9@1~vl{gC*VHC@ksB2H9lv zSEVD}f|Wxu-nYXkAA-U7GV<@Y5gr8czq2w1qYOBFUoRGLB;gDZXwQWvhdk?bFzVN` z(c#Hx=}{2E`(GFXF(d46jsSsRY0ZEpAs)lVBCV|~tdUGhkO3W|1R|4zV_LJA_~8-$ z8zV5Vwfx_Wz{uQX1u^(skWE1kKh$u+e{s-Q0)7}M`YTHZTA&Ol_W?y>3P&UeMKFZI z5FU#mU54l|K6@y6fOjv1M1YXlVh6d)#P}~hD;pH?{>l`U=_QN_@&D|Z|MsGk@01%H zR>h)34DPRAA9BM7=eLKVG>?L^1INLM=`3AN((U=*pMlUZ1|_5<8Q{ZNiKU#I=qUMD z%Wx<B!d z%vi-TF-NMQe_kvZ{NDvd?Bn8qaC4#(utWj@i97$J<8tuJ=7XgOQ9eGeHES9EpSR9mb4v0qAjHwLxu2QCENIAGjW$woVlVY$G zx_v_ze>8mamzghc68WDuMjq)u9~+LSXaq(fkDY zX^woB9^^wGpbv*WDewAODHZyZJ%Z)x;|Ty!bD%GR+6(}H_CxP&0I&`N0B-^TfRq9N z(*%20-*5&1C4`%!JuTw-?=Na~wjlKE>@kJ$P7aArH&xh8J@}+FF1@sJA~iqf7-oON z+@3{MbE@|ym;iu^^h>7n0AL(o2LRBw{OG)^57asI`b!uT5I}rgKkk6b#vhlwIsbX% z!~8XB)|*CamFSnkyOs2{yIs0Jb|RY9W*)U&#Sc@_7#-@ggJEUuTiw*nN7%981)_az28 Q0MN_LX|ZFzL*S-=0?j5J@Bjb+ literal 0 HcmV?d00001 diff --git a/bin/help.txt b/bin/help.txt new file mode 100644 index 0000000..e69de29 diff --git a/bin/items.csv b/bin/items.csv new file mode 100644 index 0000000..49dd25c --- /dev/null +++ b/bin/items.csv @@ -0,0 +1,7451 @@ +#This file belongs to Essentials. +#version: TeamCity +#If you change this file, it will not be automatically updated after the next release. +#item,id,metadata +stone,1,0 +sstone,1,0 +smoothstone,1,0 +rock,1,0 +grass,2,0 +greendirt,2,0 +greenearth,2,0 +greenland,2,0 +dirt,3,0 +earth,3,0 +land,3,0 +grasslessdirt,3,1 +grasslessearth,3,1 +grasslessland,3,1 +podzol,3,2 +cobblestone,4,0 +cstone,4,0 +cobble,4,0 +wood,5,0 +plank,5,0 +woodenplank,5,0 +woodplank,5,0 +wplank,5,0 +plankwooden,5,0 +plankwood,5,0 +plankw,5,0 +oakplank,5,0 +oakwoodenplank,5,0 +oakwoodplank,5,0 +oakwplank,5,0 +oakplankwooden,5,0 +oakplankwood,5,0 +oakplankw,5,0 +oplank,5,0 +owoodenplank,5,0 +owoodplank,5,0 +owplank,5,0 +oplankwooden,5,0 +oplankwood,5,0 +oplankw,5,0 +pineplank,5,1 +pinewoodenplank,5,1 +pinewoodplank,5,1 +pinewplank,5,1 +pineplankwooden,5,1 +pineplankwood,5,1 +pineplankw,5,1 +pplank,5,1 +pwoodenplank,5,1 +pwoodplank,5,1 +pwplank,5,1 +pplankwooden,5,1 +pplankwood,5,1 +pplankw,5,1 +darkplank,5,1 +darkwoodenplank,5,1 +darkwoodplank,5,1 +darkwplank,5,1 +darkplankwooden,5,1 +darkplankwood,5,1 +darkplankw,5,1 +dplank,5,1 +dwoodenplank,5,1 +dwoodplank,5,1 +dwplank,5,1 +dplankwooden,5,1 +dplankwood,5,1 +dplankw,5,1 +spruceplank,5,1 +sprucewoodenplank,5,1 +sprucewoodplank,5,1 +sprucewplank,5,1 +spruceplankwooden,5,1 +spruceplankwood,5,1 +spruceplankw,5,1 +splank,5,1 +swoodenplank,5,1 +swoodplank,5,1 +swplank,5,1 +splankwooden,5,1 +splankwood,5,1 +splankw,5,1 +birchplank,5,2 +birchwoodenplank,5,2 +birchwoodplank,5,2 +birchwplank,5,2 +birchplankwooden,5,2 +birchplankwood,5,2 +birchplankw,5,2 +bplank,5,2 +bwoodenplank,5,2 +bwoodplank,5,2 +bwplank,5,2 +bplankwooden,5,2 +bplankwood,5,2 +bplankw,5,2 +lightplank,5,2 +lightwoodenplank,5,2 +lightwoodplank,5,2 +lightwplank,5,2 +lightplankwooden,5,2 +lightplankwood,5,2 +lightplankw,5,2 +lplank,5,2 +lwoodenplank,5,2 +lwoodplank,5,2 +lwplank,5,2 +lplankwooden,5,2 +lplankwood,5,2 +lplankw,5,2 +whiteplank,5,2 +whitewoodenplank,5,2 +whitewoodplank,5,2 +whitewplank,5,2 +whiteplankwooden,5,2 +whiteplankwood,5,2 +whiteplankw,5,2 +wwoodenplank,5,2 +wwoodplank,5,2 +wwplank,5,2 +wplankwooden,5,2 +wplankwood,5,2 +wplankw,5,2 +jungleplank,5,3 +junglewoodenplank,5,3 +junglewoodplank,5,3 +junglewplank,5,3 +jungleplankwooden,5,3 +jungleplankwood,5,3 +jungleplankw,5,3 +jplank,5,3 +jwoodenplank,5,3 +jwoodplank,5,3 +jwplank,5,3 +jplankwooden,5,3 +jplankwood,5,3 +jplankw,5,3 +forestplank,5,3 +forestwoodenplank,5,3 +forestwoodplank,5,3 +forestwplank,5,3 +forestplankwooden,5,3 +forestplankwood,5,3 +forestplankw,5,3 +fplank,5,3 +fwoodenplank,5,3 +fwoodplank,5,3 +fwplank,5,3 +fplankwooden,5,3 +fplankwood,5,3 +fplankw,5,3 +acaciaplank,5,4 +acaciawoodenplank,5,4 +acaciawoodplank,5,4 +acaciawplank,5,4 +acaciaplankwooden,5,4 +acaciaplankwood,5,4 +acaciaplankw,5,4 +aplank,5,4 +awoodenplank,5,4 +awoodplank,5,4 +awplank,5,4 +aplankwooden,5,4 +aplankwood,5,4 +aplankw,5,4 +darkoakplank,5,5 +darkoakwoodenplank,5,5 +darkoakwoodplank,5,5 +darkoakwplank,5,5 +darkoakplankwooden,5,5 +darkoakplankwood,5,5 +darkoakplankw,5,5 +doakplank,5,5 +doakwoodenplank,5,5 +doakwoodplank,5,5 +doakwplank,5,5 +doakplankwooden,5,5 +doakplankwood,5,5 +doakplankw,5,5 +doplank,5,5 +dowoodenplank,5,5 +dowoodplank,5,5 +dowplank,5,5 +doplankwooden,5,5 +doplankwood,5,5 +doplankw,5,5 +sapling,6,0 +treesapling,6,0 +logsapling,6,0 +trunksapling,6,0 +woodsapling,6,0 +oaktreesapling,6,0 +oaklogsapling,6,0 +oaktrunksapling,6,0 +oakwoodsapling,6,0 +osapling,6,0 +otreesapling,6,0 +ologsapling,6,0 +otrunksapling,6,0 +owoodsapling,6,0 +darksapling,6,1 +darktreesapling,6,1 +darklogsapling,6,1 +darktrunksapling,6,1 +darkwoodsapling,6,1 +sprucesapling,6,1 +sprucetreesapling,6,1 +sprucelogsapling,6,1 +sprucetrunksapling,6,1 +sprucewoodsapling,6,1 +pinesapling,6,1 +pinetreesapling,6,1 +pinelogsapling,6,1 +pinetrunksapling,6,1 +pinewoodsapling,6,1 +dsapling,6,1 +dtreesapling,6,1 +dlogsapling,6,1 +dtrunksapling,6,1 +dwoodsapling,6,1 +ssapling,6,1 +streesapling,6,1 +slogsapling,6,1 +strunksapling,6,1 +swoodsapling,6,1 +psapling,6,1 +ptreesapling,6,1 +plogsapling,6,1 +ptrunksapling,6,1 +pwoodsapling,6,1 +birchsapling,6,2 +birchtreesapling,6,2 +birchlogsapling,6,2 +birchtrunksapling,6,2 +birchwoodsapling,6,2 +lightsapling,6,2 +lighttreesapling,6,2 +lightlogsapling,6,2 +lighttrunksapling,6,2 +lightwoodsapling,6,2 +whitesapling,6,2 +whitetreesapling,6,2 +whitelogsapling,6,2 +whitetrunksapling,6,2 +whitewoodsapling,6,2 +bsapling,6,2 +btreesapling,6,2 +blogsapling,6,2 +btrunksapling,6,2 +bwoodsapling,6,2 +lsapling,6,2 +ltreesapling,6,2 +llogsapling,6,2 +ltrunksapling,6,2 +lwoodsapling,6,2 +wsapling,6,2 +wtreesapling,6,2 +wlogsapling,6,2 +wtrunksapling,6,2 +wwoodsapling,6,2 +junglesapling,6,3 +jungletreesapling,6,3 +junglelogsapling,6,3 +jungletrunksapling,6,3 +junglewoodsapling,6,3 +forestsapling,6,3 +foresttreesapling,6,3 +forestlogsapling,6,3 +foresttrunksapling,6,3 +forestwoodsapling,6,3 +jsapling,6,3 +jtreesapling,6,3 +jlogsapling,6,3 +jtrunksapling,6,3 +jwoodsapling,6,3 +fsapling,6,3 +ftreesapling,6,3 +flogsapling,6,3 +ftrunksapling,6,3 +fwoodsapling,6,3 +acaciasapling,6,4 +acaciatreesapling,6,4 +acacialogsapling,6,4 +acaciatrunksapling,6,4 +acaciawoodsapling,6,4 +asapling,6,4 +atreesapling,6,4 +alogsapling,6,4 +atrunksapling,6,4 +awoodsapling,6,4 +darkoaksapling,6,5 +darkoaktreesapling,6,5 +darkoaklogsapling,6,5 +darkoaktrunksapling,6,5 +darkoakwoodsapling,6,5 +doaksapling,6,5 +doaktreesapling,6,5 +doaklogsapling,6,5 +doaktrunksapling,6,5 +dosapling,6,5 +dowoodsapling,6,5 +dotreesapling,6,5 +dologsapling,6,5 +dotrunksapling,6,5 +bedrock,7,0 +oprock,7,0 +opblock,7,0 +adminblock,7,0 +adminrock,7,0 +adminium,7,0 +water,8,0 +stationarywater,9,0 +stillwater,9,0 +swater,9,0 +lava,10,0 +stationarylava,11,0 +stilllava,11,0 +slava,11,0 +sand,12,0 +redsand,12,1 +rsand,12,1 +gravel,13,0 +goldore,14,0 +oregold,14,0 +gore,14,0 +oreg,14,0 +ogold,14,0 +goldo,14,0 +ironore,15,0 +oreiron,15,0 +irono,15,0 +oiron,15,0 +steelore,15,0 +oresteel,15,0 +steelo,15,0 +osteel,15,0 +iore,15,0 +orei,15,0 +sore,15,0 +ores,15,0 +coalore,16,0 +orecoal,16,0 +coalo,16,0 +ocoal,16,0 +core,16,0 +tree,17,0 +log,17,0 +trunk,17,0 +oak,17,0 +oaktree,17,0 +oaklog,17,0 +oaktrunk,17,0 +oakwood,17,0 +otree,17,0 +olog,17,0 +otrunk,17,0 +owood,17,0 +pine,17,1 +pinetree,17,1 +pinelog,17,1 +pinetrunk,17,1 +pinewood,17,1 +darktree,17,1 +darklog,17,1 +darktrunk,17,1 +darkwood,17,1 +spruce,17,1 +sprucetree,17,1 +sprucelog,17,1 +sprucetrunk,17,1 +sprucewood,17,1 +dtree,17,1 +dlog,17,1 +dtrunk,17,1 +dwood,17,1 +stree,17,1 +slog,17,1 +strunk,17,1 +swood,17,1 +ptree,17,1 +plog,17,1 +ptrunk,17,1 +pwood,17,1 +birch,17,2 +birchtree,17,2 +birchlog,17,2 +birchtrunk,17,2 +birchwood,17,2 +whitetree,17,2 +whitelog,17,2 +whitetrunk,17,2 +whitewood,17,2 +lighttree,17,2 +lightlog,17,2 +lighttrunk,17,2 +lightwood,17,2 +btree,17,2 +blog,17,2 +btrunk,17,2 +bwood,17,2 +wtree,17,2 +wlog,17,2 +wtrunk,17,2 +wwood,17,2 +ltree,17,2 +llog,17,2 +ltrunk,17,2 +lwood,17,2 +jungletree,17,3 +junglelog,17,3 +jungletrunk,17,3 +junglewood,17,3 +jungle,17,3 +forest,17,3 +foresttree,17,3 +forestlog,17,3 +foresttrunk,17,3 +forestwood,17,3 +jtree,17,3 +jlog,17,3 +jtrunk,17,3 +jwood,17,3 +ftree,17,3 +flog,17,3 +ftrunk,17,3 +fwood,17,3 +leaves,18,0 +leaf,18,0 +treeleaves,18,0 +logleaves,18,0 +trunkleaves,18,0 +woodleaves,18,0 +oakleaves,18,0 +oakleaf,18,0 +oleaves,18,0 +oleaf,18,0 +oaktreeleaves,18,0 +oaklogleaves,18,0 +oaktrunkleaves,18,0 +oakwoodleaves,18,0 +otreeleaves,18,0 +ologleaves,18,0 +otrunkleaves,18,0 +owoodleaves,18,0 +treeleaf,18,0 +logleaf,18,0 +trunkleaf,18,0 +woodleaf,18,0 +oaktreeleaf,18,0 +oaklogleaf,18,0 +oaktrunkleaf,18,0 +oakwoodleaf,18,0 +otreeleaf,18,0 +ologleaf,18,0 +otrunkleaf,18,0 +owoodleaf,18,0 +pineleaves,18,1 +pineleaf,18,1 +pleaves,18,1 +pleaf,18,1 +pinetreeleaves,18,1 +pinelogleaves,18,1 +pinetrunkleaves,18,1 +pinewoodleaves,18,1 +ptreeleaves,18,1 +plogleaves,18,1 +ptrunkleaves,18,1 +pwoodleaves,18,1 +spruceleaves,18,1 +spruceleaf,18,1 +sleaves,18,1 +sleaf,18,1 +sprucetreeleaves,18,1 +sprucelogleaves,18,1 +sprucetrunkleaves,18,1 +sprucewoodleaves,18,1 +streeleaves,18,1 +slogleaves,18,1 +strunkleaves,18,1 +swoodleaves,18,1 +darkleaves,18,1 +darkleaf,18,1 +dleaves,18,1 +dleaf,18,1 +darktreeleaves,18,1 +darklogleaves,18,1 +darktrunkleaves,18,1 +darkwoodleaves,18,1 +dtreeleaves,18,1 +dlogleaves,18,1 +dtrunkleaves,18,1 +dwoodleaves,18,1 +sprucetreeleaf,18,1 +sprucelogleaf,18,1 +sprucetrunkleaf,18,1 +sprucewoodleaf,18,1 +streeleaf,18,1 +slogleaf,18,1 +strunkleaf,18,1 +swoodleaf,18,1 +pinetreeleaf,18,1 +pinelogleaf,18,1 +pinetrunkleaf,18,1 +pinewoodleaf,18,1 +ptreeleaf,18,1 +plogleaf,18,1 +ptrunkleaf,18,1 +pwoodleaf,18,1 +darktreeleaf,18,1 +darklogleaf,18,1 +darktrunkleaf,18,1 +darkwoodleaf,18,1 +dtreeleaf,18,1 +dlogleaf,18,1 +dtrunkleaf,18,1 +dwoodleaf,18,1 +birchleaves,18,2 +birchleaf,18,2 +bleaves,18,2 +bleaf,18,2 +birchtreeleaves,18,2 +birchlogleaves,18,2 +birchtrunkleaves,18,2 +birchwoodleaves,18,2 +btreeleaves,18,2 +blogleaves,18,2 +btrunkleaves,18,2 +bwoodleaves,18,2 +lightleaves,18,2 +lightleaf,18,2 +lleaves,18,2 +lleaf,18,2 +lighttreeleaves,18,2 +lightlogleaves,18,2 +lighttrunkleaves,18,2 +lightwoodleaves,18,2 +ltreeleaves,18,2 +llogleaves,18,2 +ltrunkleaves,18,2 +lwoodleaves,18,2 +whiteleaves,18,2 +whiteleaf,18,2 +wleaves,18,2 +wleaf,18,2 +whitetreeleaves,18,2 +whitelogleaves,18,2 +whitetrunkleaves,18,2 +whitewoodleaves,18,2 +wtreeleaves,18,2 +wlogleaves,18,2 +wtrunkleaves,18,2 +wwoodleaves,18,2 +birchtreeleaf,18,2 +birchlogleaf,18,2 +birchtrunkleaf,18,2 +birchwoodleaf,18,2 +btreeleaf,18,2 +blogleaf,18,2 +btrunkleaf,18,2 +bwoodleaf,18,2 +lighttreeleaf,18,2 +lightlogleaf,18,2 +lighttrunkleaf,18,2 +lightwoodleaf,18,2 +ltreeleaf,18,2 +llogleaf,18,2 +ltrunkleaf,18,2 +lwoodleaf,18,2 +whitetreeleaf,18,2 +whitelogleaf,18,2 +whitetrunkleaf,18,2 +whitewoodleaf,18,2 +wtreeleaf,18,2 +wlogleaf,18,2 +wtrunkleaf,18,2 +wwoodleaf,18,2 +jungleleaves,18,3 +jungleleaf,18,3 +jleaves,18,3 +jleaf,18,3 +jungletreeleaves,18,3 +junglelogleaves,18,3 +jungletrunkleaves,18,3 +junglewoodleaves,18,3 +jtreeleaves,18,3 +jlogleaves,18,3 +jtrunkleaves,18,3 +jwoodleaves,18,3 +forestleaves,18,3 +forestleaf,18,3 +fleaves,18,3 +fleaf,18,3 +foresttreeleaves,18,3 +forestlogleaves,18,3 +foresttrunkleaves,18,3 +forestwoodleaves,18,3 +ftreeleaves,18,3 +flogleaves,18,3 +ftrunkleaves,18,3 +fwoodleaves,18,3 +jungletreeleaf,18,3 +junglelogleaf,18,3 +jungletrunkleaf,18,3 +junglewoodleaf,18,3 +jtreeleaf,18,3 +jlogleaf,18,3 +jtrunkleaf,18,3 +jwoodleaf,18,3 +foresttreeleaf,18,3 +forestlogleaf,18,3 +foresttrunkleaf,18,3 +forestwoodleaf,18,3 +ftreeleaf,18,3 +flogleaf,18,3 +ftrunkleaf,18,3 +fwoodleaf,18,3 +sponge,19,0 +glass,20,0 +blockglass,20,0 +glassblock,20,0 +lapislazuliore,21,0 +lapislazulio,21,0 +orelapislazuli,21,0 +olapislazuli,21,0 +lapisore,21,0 +lapiso,21,0 +orelapis,21,0 +olapis,21,0 +lore,21,0 +orel,21,0 +lapislazuliblock,22,0 +blocklapislazuli,22,0 +lapisblock,22,0 +blocklapis,22,0 +lblock,22,0 +blockl,22,0 +dispenser,23,0 +dispense,23,0 +sandstone,24,0 +sastone,24,0 +creepersandstone,24,1 +creepersastone,24,1 +creepsandstone,24,1 +creepsastone,24,1 +csandstone,24,1 +csastone,24,1 +hieroglyphicsandstone,24,1 +hieroglyphicsastone,24,1 +hieroglyphsandstone,24,1 +hieroglyphsastone,24,1 +hsandstone,24,1 +hsastone,24,1 +pyramidsandstone,24,1 +pyramidsastone,24,1 +psandstone,24,1 +psastone,24,1 +chiseledsandstone,24,1 +chiseledsastone,24,1 +chiselsandstone,24,1 +chiselsastone,24,1 +smoothsandstone,24,2 +smoothsastone,24,2 +ssandstone,24,2 +smsastone,24,2 +ssastone,24,2 +noteblock,25,0 +musicblock,25,0 +nblock,25,0 +mblock,25,0 +poweredtrack,27,0 +poweredrails,27,0 +poweredrail,27,0 +boostertrack,27,0 +boosterrails,27,0 +boosterrail,27,0 +powertrack,27,0 +powerrails,27,0 +powerrail,27,0 +boosttrack,27,0 +boostrails,27,0 +boostrail,27,0 +ptrack,27,0 +prails,27,0 +prail,27,0 +btrack,27,0 +brails,27,0 +brail,27,0 +detectortrack,28,0 +detectorrails,28,0 +detectorrail,28,0 +detectingtrack,28,0 +detectingrails,28,0 +detectingrail,28,0 +detecttrack,28,0 +detectrails,28,0 +detectrail,28,0 +dtrack,28,0 +drails,28,0 +drail,28,0 +stickypistonbase,29,0 +stickypiston,29,0 +stickpistonbase,29,0 +stickpiston,29,0 +stickyp,29,0 +spistonbase,29,0 +spiston,29,0 +pistonstickybase,29,0 +pistonsticky,29,0 +pistonstickbase,29,0 +pistonstick,29,0 +pistonsbase,29,0 +pistons,29,0 +psticky,29,0 +pstick,29,0 +spiderweb,30,0 +cobweb,30,0 +sweb,30,0 +cweb,30,0 +web,30,0 +longgrass,31,1 +tallgrass,31,1 +wildgrass,31,1 +grasslong,31,1 +grasstall,31,1 +grasswild,31,1 +lgrass,31,1 +tgrass,31,1 +wgrass,31,1 +fern,31,2 +bush,31,2 +deadshrub,32,0 +dshrub,32,0 +deadbush,32,0 +dbush,32,0 +deadsapling,32,0 +piston,33,0 +pistonbase,33,0 +pistonblock,33,0 +whitewool,35,0 +whitecloth,35,0 +whitecotton,35,0 +wcloth,35,0 +wwool,35,0 +wcotton,35,0 +cloth,35,0 +wool,35,0 +cotton,35,0 +orangewool,35,1 +orangecloth,35,1 +orangecotton,35,1 +ocloth,35,1 +owool,35,1 +ocotton,35,1 +magentawool,35,2 +magentacloth,35,2 +magentacotton,35,2 +mcloth,35,2 +mwool,35,2 +mcotton,35,2 +lightbluewool,35,3 +lightbluecloth,35,3 +lightbluecotton,35,3 +lbluecloth,35,3 +lbluewool,35,3 +lbluecotton,35,3 +lightblucloth,35,3 +lightbluwool,35,3 +lightblucotton,35,3 +lblucloth,35,3 +lbluwool,35,3 +lblucotton,35,3 +lbcloth,35,3 +lbwool,35,3 +lbcotton,35,3 +yellowwool,35,4 +yellowcloth,35,4 +yellowcotton,35,4 +ycloth,35,4 +ywool,35,4 +ycotton,35,4 +lightgreenwool,35,5 +lightgreencloth,35,5 +lightgreencotton,35,5 +lgreencloth,35,5 +lgreenwool,35,5 +lgreencotton,35,5 +lightgrecloth,35,5 +lightgrewool,35,5 +lightgrecotton,35,5 +lgrecloth,35,5 +lgrewool,35,5 +lgrecotton,35,5 +limecloth,35,5 +limewool,35,5 +limecotton,35,5 +lcloth,35,5 +lwool,35,5 +lcotton,35,5 +pinkwool,35,6 +pinkcloth,35,6 +pinkcotton,35,6 +picloth,35,6 +piwool,35,6 +picotton,35,6 +darkgraywool,35,7 +darkgraycloth,35,7 +darkgraycotton,35,7 +darkgreywool,35,7 +darkgreycloth,35,7 +darkgreycotton,35,7 +dgraycloth,35,7 +dgraywool,35,7 +dgraycotton,35,7 +dgreycloth,35,7 +dgreywool,35,7 +dgreycotton,35,7 +darkgracloth,35,7 +darkgrawool,35,7 +darkgracotton,35,7 +dgracloth,35,7 +dgrawool,35,7 +dgracotton,35,7 +graycloth,35,7 +graywool,35,7 +graycotton,35,7 +greycloth,35,7 +greywool,35,7 +greycotton,35,7 +gracloth,35,7 +grawool,35,7 +gracotton,35,7 +lightgraywool,35,8 +lightgraycloth,35,8 +lightgraycotton,35,8 +lgraycloth,35,8 +lgraywool,35,8 +lgraycotton,35,8 +lightgreywool,35,8 +lightgreycloth,35,8 +lightgreycotton,35,8 +lgreycloth,35,8 +lgreywool,35,8 +lgreycotton,35,8 +lightgracloth,35,8 +lightgrawool,35,8 +lightgracotton,35,8 +lgracloth,35,8 +lgrawool,35,8 +lgracotton,35,8 +silvercloth,35,8 +silverwool,35,8 +silvercotton,35,8 +sicloth,35,8 +siawool,35,8 +siacotton,35,8 +cyanwool,35,9 +cyancloth,35,9 +cyancotton,35,9 +ccloth,35,9 +cwool,35,9 +ccotton,35,9 +purplewool,35,10 +purplecloth,35,10 +purplecotton,35,10 +pucloth,35,10 +puwool,35,10 +pucotton,35,10 +bluewool,35,11 +bluecloth,35,11 +bluecotton,35,11 +blucloth,35,11 +bluwool,35,11 +blucotton,35,11 +brownwool,35,12 +browncloth,35,12 +browncotton,35,12 +brocloth,35,12 +browool,35,12 +brocotton,35,12 +darkgreenwool,35,13 +darkgreencloth,35,13 +darkgreencotton,35,13 +dgreencloth,35,13 +dgreenwool,35,13 +dgreencotton,35,13 +greencloth,35,13 +greenwool,35,13 +greencotton,35,13 +darkgrecloth,35,13 +darkgrewool,35,13 +darkgrecotton,35,13 +dgrecloth,35,13 +dgrewool,35,13 +dgrecotton,35,13 +grecloth,35,13 +grewool,35,13 +grecotton,35,13 +redwool,35,14 +redcloth,35,14 +redcotton,35,14 +rcloth,35,14 +rwool,35,14 +rcotton,35,14 +blackwool,35,15 +blackcloth,35,15 +blackcotton,35,15 +blacloth,35,15 +blawool,35,15 +blacotton,35,15 +dandelion,37,0 +yellowdandelion,37,0 +ydandelion,37,0 +yellowflower,37,0 +yflower,37,0 +flower,37,0 +rose,38,0 +redrose,38,0 +rrose,38,0 +redflower,38,0 +rflower,38,0 +poppy,38,0 +redpoppy,38,0 +blueorchid,38,1 +cyanorchid,38,1 +lightblueorchid,38,1 +lblueorchid,38,1 +orchid,38,1 +allium,38,2 +magentaallium,38,2 +azurebluet,38,3 +whiteazurebluet,38,3 +abluet,38,3 +azureb,38,3 +houstonia,38,3 +redtulip,38,4 +tulipred,38,4 +rtulip,38,4 +tulipr,38,4 +orangetulip,38,5 +tuliporange,38,5 +otulip,38,5 +tulipo,38,5 +whitetulip,38,6 +tulipwhite,38,6 +wtulip,38,6 +tulipw,38,6 +pinktulip,38,7 +tulippink,38,7 +ptulip,38,7 +tulipp,38,7 +oxeye,38,8 +daisy,38,8 +oxeyedaisy,38,8 +daisyoxeye,38,8 +moondaisy,38,8 +daisymoon,38,8 +lightgrayoxeye,38,8 +lgrayoxeye,38,8 +lightgreyoxeye,38,8 +lgreyoxeye,38,8 +brownmushroom,39,0 +brownshroom,39,0 +brownmush,39,0 +bmushroom,39,0 +bshroom,39,0 +bmush,39,0 +redmushroom,40,0 +redshroom,40,0 +redmush,40,0 +rmushroom,40,0 +rshroom,40,0 +rmush,40,0 +goldblock,41,0 +blockgold,41,0 +gblock,41,0 +blockg,41,0 +ironblock,42,0 +steelblock,42,0 +blockiron,42,0 +blocksteel,42,0 +iblock,42,0 +stblock,42,0 +blocki,42,0 +blockst,42,0 +stonedoublestep,43,0 +stonedstep,43,0 +sdoublestep,43,0 +sdstep,43,0 +doublestonestep,43,0 +dstonestep,43,0 +doublesstep,43,0 +doublestep,43,0 +dstep,43,0 +stonedoubleslab,43,0 +stonedslab,43,0 +sdoubleslab,43,0 +sdslab,43,0 +doublestoneslab,43,0 +dstoneslab,43,0 +doublesslab,43,0 +doubleslab,43,0 +dslab,43,0 +stonedoublehalfblock,43,0 +stonedhalfblock,43,0 +sdoublehalfblock,43,0 +sdhalfblock,43,0 +doublestonehalfblock,43,0 +dstonehalfblock,43,0 +doubleshalfblock,43,0 +doublehalfblock,43,0 +dhalfblock,43,0 +sandstonedoublestep,43,1 +sandstonedstep,43,1 +sstonedoublestep,43,1 +sstonedstep,43,1 +ssdoublestep,43,1 +ssdstep,43,1 +doublesandstonestep,43,1 +dsandstonestep,43,1 +doublesstonestep,43,1 +dsstonestep,43,1 +doublessstep,43,1 +dsstep,43,1 +sandstonedoubleslab,43,1 +sandstonedslab,43,1 +sstonedoubleslab,43,1 +sstonedslab,43,1 +ssdoubleslab,43,1 +ssdslab,43,1 +doublesandstoneslab,43,1 +dsandstoneslab,43,1 +doublesstoneslab,43,1 +dsstoneslab,43,1 +doublessslab,43,1 +dsslab,43,1 +sandstonedoublehalfblock,43,1 +sandstonedhalfblock,43,1 +sstonedoublehalfblock,43,1 +sstonedhalfblock,43,1 +ssdoublehalfblock,43,1 +ssdhalfblock,43,1 +doublesandstonehalfblock,43,1 +dsandstonehalfblock,43,1 +doublesstonehalfblock,43,1 +dsstonehalfblock,43,1 +doublesshalfblock,43,1 +dsshalfblock,43,1 +plankstonedoublestep,43,2 +woodenstonedoublestep,43,2 +woodenstonedstep,43,2 +woodstonedoublestep,43,2 +woodstonedstep,43,2 +wstonedoublestep,43,2 +wstonedstep,43,2 +doublewoodenstonestep,43,2 +dwoodenstonestep,43,2 +doublewoodstonestep,43,2 +dwoodstonestep,43,2 +doublewstonestep,43,2 +dwstonestep,43,2 +woodenstonedoubleslab,43,2 +woodenstonedslab,43,2 +woodstonedoubleslab,43,2 +woodstonedslab,43,2 +wstonedoubleslab,43,2 +wstonedslab,43,2 +doublewoodenstoneslab,43,2 +dwoodenstoneslab,43,2 +doublewoodstoneslab,43,2 +dwoodstoneslab,43,2 +doublewstoneslab,43,2 +dwstoneslab,43,2 +woodenstonedoublehalfblock,43,2 +woodenstonedhalfblock,43,2 +woodstonedoublehalfblock,43,2 +woodstonedhalfblock,43,2 +wstonedoublehalfblock,43,2 +wstonedhalfblock,43,2 +doublewoodenstonehalfblock,43,2 +dwoodenstonehalfblock,43,2 +doublewoodstonehalfblock,43,2 +dwoodstonehalfblock,43,2 +doublewstonehalfblock,43,2 +dwstonehalfblock,43,2 +cobblestonedoublestep,43,3 +cobblestonedstep,43,3 +cobbledoublestep,43,3 +cobbledstep,43,3 +cstonedoublestep,43,3 +cstonedstep,43,3 +csdoublestep,43,3 +csdstep,43,3 +doublecobblestonestep,43,3 +dcobblestonestep,43,3 +doublecobblestep,43,3 +dcobblestep,43,3 +doublecstonestep,43,3 +dcstonestep,43,3 +doublecsstep,43,3 +dcsstep,43,3 +cobblestonedoubleslab,43,3 +cobblestonedslab,43,3 +cobbledoubleslab,43,3 +cobbledslab,43,3 +cstonedoubleslab,43,3 +cstonedslab,43,3 +csdoubleslab,43,3 +csdslab,43,3 +doublecobblestoneslab,43,3 +dcobblestoneslab,43,3 +doublecobbleslab,43,3 +dcobbleslab,43,3 +doublecstoneslab,43,3 +dcstoneslab,43,3 +doublecsslab,43,3 +dcsslab,43,3 +cobblestonedoublehalfblock,43,3 +cobblestonedhalfblock,43,3 +cobbledoublehalfblock,43,3 +cobbledhalfblock,43,3 +cstonedoublehalfblock,43,3 +cstonedhalfblock,43,3 +csdoublehalfblock,43,3 +csdhalfblock,43,3 +doublecobblestonehalfblock,43,3 +dcobblestonehalfblock,43,3 +doublecobblehalfblock,43,3 +dcobblehalfblock,43,3 +doublecstonehalfblock,43,3 +dcstonehalfblock,43,3 +doublecshalfblock,43,3 +dcshalfblock,43,3 +brickdoublestep,43,4 +brickdstep,43,4 +bdoublestep,43,4 +bdstep,43,4 +brickdoubleslab,43,4 +brickdslab,43,4 +bdoubleslab,43,4 +bdslab,43,4 +doublebrickstep,43,4 +dbrickstep,43,4 +doublebstep,43,4 +dbstep,43,4 +doublebrickslab,43,4 +dbrickslab,43,4 +doublebslab,43,4 +dbslab,43,4 +brickdoublehalfblock,43,4 +brickdhalfblock,43,4 +bdoublehalfblock,43,4 +bdhalfblock,43,4 +doublebrickhalfblock,43,4 +dbrickhalfblock,43,4 +doublebhalfblock,43,4 +dbhalfblock,43,4 +stonebrickdoublestep,43,5 +stonebrickdstep,43,5 +stonebdoublestep,43,5 +stonebdstep,43,5 +sbrickdoublestep,43,5 +sbrickdstep,43,5 +sbdoublestep,43,5 +sbdstep,43,5 +stonebrickdoubleslab,43,5 +stonebrickdslab,43,5 +stonebdoubleslab,43,5 +stonebdslab,43,5 +sbrickdoubleslab,43,5 +sbrickdslab,43,5 +sbdoubleslab,43,5 +sbdslab,43,5 +doublestonebrickstep,43,5 +dstonebrickstep,43,5 +doublestonebstep,43,5 +dstonebstep,43,5 +doublesbrickstep,43,5 +dsbrickstep,43,5 +doublesbstep,43,5 +dsbstep,43,5 +doublestonebrickslab,43,5 +dstonebrickslab,43,5 +doublestonebslab,43,5 +dstonebslab,43,5 +doublesbrickslab,43,5 +dsbrickdslab,43,5 +doublesbslab,43,5 +dsbslab,43,5 +stonebrickdoublehalfblock,43,5 +stonebrickdhalfblock,43,5 +stonebdoublehalfblock,43,5 +stonebdhalfblock,43,5 +sbrickdoublehalfblock,43,5 +sbrickdhalfblock,43,5 +sbdoublehalfblock,43,5 +sbdhalfblock,43,5 +doublestonebrickhalfblock,43,5 +dstonebrickhalfblock,43,5 +doublestonebhalfblock,43,5 +dstonebhalfblock,43,5 +doublesbrickhalfblock,43,5 +dsbrickhalfblock,43,5 +doublesbhalfblock,43,5 +dsbhalfblock,43,5 +netherbrickdoubleslab,43,6 +hellbrickdoubleslab,43,6 +nbrickdoubleslab,43,6 +hbrickdoubleslab,43,6 +netherdoubleslab,43,6 +helldoubleslab,43,6 +nbdoubleslab,43,6 +hbdoubleslab,43,6 +hdoubleslab,43,6 +ndoubleslab,43,6 +netherbrickdoublestep,43,6 +hellbrickdoublestep,43,6 +nbrickdoublestep,43,6 +hbrickdoublestep,43,6 +netherdoublestep,43,6 +helldoublestep,43,6 +nbdoublestep,43,6 +hbdoublestep,43,6 +ndoublestep,43,6 +hdoublestep,43,6 +netherbrickdoublehalfblock,43,6 +hellbrickdoublehalfblock,43,6 +nbrickdoublehalfblock,43,6 +hbrickdoublehalfblock,43,6 +netherdoublehalfblock,43,6 +helldoublehalfblock,43,6 +nbdoublehalfblock,43,6 +hbdoublehalfblock,43,6 +ndoublehalfblock,43,6 +hdoublehalfblock,43,6 +netherbrickdslab,43,6 +hellbrickdslab,43,6 +nbrickdslab,43,6 +hbrickdslab,43,6 +netherdslab,43,6 +helldslab,43,6 +nbdslab,43,6 +hbdslab,43,6 +hdslab,43,6 +ndslab,43,6 +netherbrickdstep,43,6 +hellbrickdstep,43,6 +nbrickdstep,43,6 +hbrickdstep,43,6 +netherdstep,43,6 +helldstep,43,6 +nbdstep,43,6 +hbdstep,43,6 +ndstep,43,6 +hdstep,43,6 +netherbrickdhalfblock,43,6 +hellbrickdhalfblock,43,6 +nbrickdhalfblock,43,6 +hbrickdhalfblock,43,6 +netherdhalfblock,43,6 +helldhalfblock,43,6 +nbdhalfblock,43,6 +hbdhalfblock,43,6 +ndhalfblock,43,6 +hdhalfblock,43,6 +doublenetherbrickslab,43,6 +doublehellbrickslab,43,6 +doublenbrickslab,43,6 +doublehbrickslab,43,6 +doublenetherslab,43,6 +doublehellslab,43,6 +doublenbslab,43,6 +doublehbslab,43,6 +doublehslab,43,6 +doublenslab,43,6 +doublenetherbrickstep,43,6 +doublehellbrickstep,43,6 +doublenbrickstep,43,6 +doublehbrickstep,43,6 +doublenetherstep,43,6 +doublehellstep,43,6 +doublenbstep,43,6 +doublehbstep,43,6 +doublenstep,43,6 +doublehstep,43,6 +doublenetherbrickhalfblock,43,6 +doublehellbrickhalfblock,43,6 +doublenbrickhalfblock,43,6 +doublehbrickhalfblock,43,6 +doublenetherhalfblock,43,6 +doublehellhalfblock,43,6 +doublenbhalfblock,43,6 +doublehbhalfblock,43,6 +doublenhalfblock,43,6 +doublehhalfblock,43,6 +dnetherbrickslab,43,6 +dhellbrickslab,43,6 +dnbrickslab,43,6 +dhbrickslab,43,6 +dnetherslab,43,6 +dhellslab,43,6 +dnbslab,43,6 +dhbslab,43,6 +dhslab,43,6 +dnslab,43,6 +dnetherbrickstep,43,6 +dhellbrickstep,43,6 +dnbrickstep,43,6 +dhbrickstep,43,6 +dnetherstep,43,6 +dhellstep,43,6 +dnbstep,43,6 +dhbstep,43,6 +dnstep,43,6 +dhstep,43,6 +dnetherbrickhalfblock,43,6 +dhellbrickhalfblock,43,6 +dnbrickhalfblock,43,6 +dhbrickhalfblock,43,6 +dnetherhalfblock,43,6 +dhellhalfblock,43,6 +dnbhalfblock,43,6 +dhbhalfblock,43,6 +dnhalfblock,43,6 +dhhalfblock,43,6 +netherquartzdoublestep,43,7 +hellquartzdoublestep,43,7 +deathquartzdoublestep,43,7 +nquartzdoublestep,43,7 +hquartzdoublestep,43,7 +dquartzdoublestep,43,7 +quartzdoublestep,43,7 +nqdoublestep,43,7 +hqdoublestep,43,7 +dqdoublestep,43,7 +qdoublestep,43,7 +netherquartzdoubleslab,43,7 +hellquartzdoubleslab,43,7 +deathquartzdoubleslab,43,7 +nquartzdoubleslab,43,7 +hquartzdoubleslab,43,7 +dquartzdoubleslab,43,7 +quartzdoubleslab,43,7 +nqdoubleslab,43,7 +hqdoubleslab,43,7 +dqdoubleslab,43,7 +qdoubleslab,43,7 +netherquartzdoublehalfblock,43,7 +hellquartzdoublehalfblock,43,7 +deathquartzdoublehalfblock,43,7 +nquartzdoublehalfblock,43,7 +hquartzdoublehalfblock,43,7 +dquartzdoublehalfblock,43,7 +quartzdoublehalfblock,43,7 +nqdoublehalfblock,43,7 +hqdoublehalfblock,43,7 +dqdoublehalfblock,43,7 +qdoublehalfblock,43,7 +netherquartzdslab,43,7 +hellquartzdslab,43,7 +deathquartzdslab,43,7 +nquartzdslab,43,7 +hquartzdslab,43,7 +dquartzdslab,43,7 +quartzdslab,43,7 +nqdslab,43,7 +hqdslab,43,7 +dqdslab,43,7 +qdslab,43,7 +netherquartzdstep,43,7 +hellquartzdstep,43,7 +deathquartzdstep,43,7 +nquartzdstep,43,7 +hquartzdstep,43,7 +dquartzdstep,43,7 +quartzdstep,43,7 +nqdstep,43,7 +hqdstep,43,7 +dqdstep,43,7 +qdstep,43,7 +netherquartzdhalfblock,43,7 +hellquartzdhalfblock,43,7 +deathquartzdhalfblock,43,7 +nquartzdhalfblock,43,7 +hquartzdhalfblock,43,7 +dquartzdhalfblock,43,7 +quartzdhalfblock,43,7 +nqdhalfblock,43,7 +hqdhalfblock,43,7 +dqdhalfblock,43,7 +qdhalfblock,43,7 +doublenetherquartzslab,43,7 +doublehellquartzslab,43,7 +doubledeathquartzslab,43,7 +doublenquartzslab,43,7 +doublehquartzslab,43,7 +doubledquartzslab,43,7 +doublequartzslab,43,7 +doublenqslab,43,7 +doublehqslab,43,7 +doubledqslab,43,7 +doubleqslab,43,7 +doublenetherquartzstep,43,7 +doublehellquartzstep,43,7 +doubledeathquartzstep,43,7 +doublenquartzstep,43,7 +doublehquartzstep,43,7 +doubledquartzstep,43,7 +doublequartzstep,43,7 +doublenqstep,43,7 +doublehqstep,43,7 +doubledqstep,43,7 +doubleqstep,43,7 +doublenetherquartzhalfblock,43,7 +doublehellquartzhalfblock,43,7 +doubledeathquartzhalfblock,43,7 +doublenquartzhalfblock,43,7 +doublehquartzhalfblock,43,7 +doubledquartzhalfblock,43,7 +doublequartzhalfblock,43,7 +doublenqhalfblock,43,7 +doublehqhalfblock,43,7 +doubledqhalfblock,43,7 +doubleqhalfblock,43,7 +dnetherquartzslab,43,7 +dhellquartzslab,43,7 +ddeathquartzslab,43,7 +dnquartzslab,43,7 +dhquartzslab,43,7 +ddquartzslab,43,7 +dnqslab,43,7 +dhqslab,43,7 +ddqslab,43,7 +dnetherquartzstep,43,7 +dhellquartzstep,43,7 +ddeathquartzstep,43,7 +dnquartzstep,43,7 +dhquartzstep,43,7 +ddquartzstep,43,7 +dnqstep,43,7 +dhqstep,43,7 +ddqstep,43,7 +dnetherquartzhalfblock,43,7 +dhellquartzhalfblock,43,7 +ddeathquartzhalfblock,43,7 +dnquartzhalfblock,43,7 +dhquartzhalfblock,43,7 +ddquartzhalfblock,43,7 +dnqhalfblock,43,7 +dhqhalfblock,43,7 +ddqhalfblock,43,7 +smoothstonedoubleslab,43,8 +smoothstonedoublestep,43,8 +smoothstonedoublehalfblock,43,8 +smoothstonedslab,43,8 +smoothstonedstep,43,8 +smoothstonedhalfblock,43,8 +doublesmoothstoneslab,43,8 +doublesmoothstonestep,43,8 +doublesmoothstonehalfblock,43,8 +dsmoothstoneslab,43,8 +dsmoothstonestep,43,8 +dsmoothstonehalfblock,43,8 +smoothsandstonedoubleslab,43,9 +ssandstonedoubleslab,43,9 +ssstonedoubleslab,43,9 +sssdoubleslab,43,9 +smoothsandstonedoublestep,43,9 +ssandstonedoublestep,43,9 +ssstonedoublestep,43,9 +sssdoublestep,43,9 +smoothsandstonedoublehalfblock,43,9 +ssandstonedoublehalfblock,43,9 +ssstonedoublehalfblock,43,9 +sssdoublehalfblock,43,9 +smoothsandstonedslab,43,9 +ssandstonedslab,43,9 +ssstonedslab,43,9 +sssdslab,43,9 +smoothsandstonedstep,43,9 +ssandstonedstep,43,9 +ssstonedstep,43,9 +sssdstep,43,9 +smoothsandstonedhalfblock,43,9 +ssandstonedhalfblock,43,9 +ssstonedhalfblock,43,9 +sssdhalfblock,43,9 +doublesmoothsandstoneslab,43,9 +doublessandstoneslab,43,9 +doublessstoneslab,43,9 +doublesssslab,43,9 +doublesmoothsandstonestep,43,9 +doublessandstonestep,43,9 +doublessstonestep,43,9 +doublesssstep,43,9 +doublesmoothsandstonehalfblock,43,9 +doublessandstonehalfblock,43,9 +doublessstonehalfblock,43,9 +doublessshalfblock,43,9 +dsmoothsandstoneslab,43,9 +dssandstoneslab,43,9 +dssstoneslab,43,9 +dsssslab,43,9 +dsmoothsandstonestep,43,9 +dssandstonestep,43,9 +dssstonestep,43,9 +dsssstep,43,9 +dsmoothsandstonehalfblock,43,9 +dssandstonehalfblock,43,9 +dssstonehalfblock,43,9 +dssshalfblock,43,9 +smoothstonestep,44,0 +stonestep,44,0 +sstep,44,0 +step,44,0 +smoothstoneslab,44,0 +stoneslab,44,0 +sslab,44,0 +slab,44,0 +smoothstonehalfblock,44,0 +stonehalfblock,44,0 +shalfblock,44,0 +halfblock,44,0 +sandstonestep,44,1 +sstonestep,44,1 +ssstep,44,1 +sandstoneslab,44,1 +sstoneslab,44,1 +ssslab,44,1 +sandstonehalfblock,44,1 +sstonehalfblock,44,1 +sshalfblock,44,1 +woodenstonestep,44,2 +woodstonestep,44,2 +wstonestep,44,2 +woodenstoneslab,44,2 +woodstoneslab,44,2 +wstoneslab,44,2 +woodenstonehalfblock,44,2 +woodstonehalfblock,44,2 +wstonehalfblock,44,2 +cobblestonestep,44,3 +cobblestep,44,3 +cstonestep,44,3 +csstep,44,3 +cobblestoneslab,44,3 +cobbleslab,44,3 +cstoneslab,44,3 +csslab,44,3 +cobblestonehalfblock,44,3 +cobblehalfblock,44,3 +cstonehalfblock,44,3 +cshalfblock,44,3 +brickstep,44,4 +bstep,44,4 +brickslab,44,4 +bslab,44,4 +brickhalfblock,44,4 +bhalfblock,44,4 +stonebrickstep,44,5 +stonebstep,44,5 +sbrickstep,44,5 +sbstep,44,5 +stonebrickslab,44,5 +stonebslab,44,5 +sbrickslab,44,5 +sbslab,44,5 +stonebrickhalfblock,44,5 +stonebhalfblock,44,5 +sbrickhalfblock,44,5 +sbhalfblock,44,5 +netherbrickslab,44,6 +hellbrickslab,44,6 +nbrickslab,44,6 +hbrickslab,44,6 +netherslab,44,6 +hellslab,44,6 +nbslab,44,6 +hbslab,44,6 +hslab,44,6 +nslab,44,6 +netherbrickstep,44,6 +hellbrickstep,44,6 +nbrickstep,44,6 +hbrickstep,44,6 +netherstep,44,6 +hellstep,44,6 +nbstep,44,6 +hbstep,44,6 +nstep,44,6 +hstep,44,6 +netherbrickhalfblock,44,6 +hellbrickhalfblock,44,6 +nbrickhalfblock,44,6 +hbrickhalfblock,44,6 +netherhalfblock,44,6 +hellhalfblock,44,6 +nbhalfblock,44,6 +hbhalfblock,44,6 +nhalfblock,44,6 +hhalfblock,44,6 +netherquartzstep,44,7 +hellquartzstep,44,7 +deathquartzstep,44,7 +nquartzstep,44,7 +hquartzstep,44,7 +dquartzstep,44,7 +quartzstep,44,7 +nqstep,44,7 +hqstep,44,7 +dqstep,44,7 +qstep,44,7 +netherquartzslab,44,7 +hellquartzslab,44,7 +deathquartzslab,44,7 +nquartzslab,44,7 +hquartzslab,44,7 +dquartzslab,44,7 +quartzslab,44,7 +nqslab,44,7 +hqslab,44,7 +dqslab,44,7 +qslab,44,7 +netherquartzhalfblock,44,7 +hellquartzhalfblock,44,7 +deathquartzhalfblock,44,7 +nquartzhalfblock,44,7 +hquartzhalfblock,44,7 +dquartzhalfblock,44,7 +quartzhalfblock,44,7 +nqhalfblock,44,7 +hqhalfblock,44,7 +dqhalfblock,44,7 +qhalfblock,44,7 +brickblock,45,0 +blockbrick,45,0 +bblock,45,0 +blockb,45,0 +tnt,46,0 +tntblock,46,0 +blocktnt,46,0 +bombblock,46,0 +blockbomb,46,0 +dynamiteblock,46,0 +blockdynamite,46,0 +bomb,46,0 +dynamite,46,0 +bookcase,47,0 +casebook,47,0 +bookshelf,47,0 +shelfbook,47,0 +bookblock,47,0 +blockbook,47,0 +mossycobblestone,48,0 +mosscobblestone,48,0 +mcobblestone,48,0 +mossycobble,48,0 +mosscobble,48,0 +mcobble,48,0 +mossstone,48,0 +mossystone,48,0 +mstone,48,0 +obsidian,49,0 +obsi,49,0 +obby,49,0 +torch,50,0 +burningstick,50,0 +burnstick,50,0 +fire,51,0 +flame,51,0 +flames,51,0 +mobspawner,52,0 +mobcage,52,0 +monsterspawner,52,0 +monstercage,52,0 +mspawner,52,0 +mcage,52,0 +spawner,52,0 +cage,52,0 +woodenstairs,53,0 +woodstairs,53,0 +wstairs,53,0 +woodenstair,53,0 +woodstair,53,0 +wstair,53,0 +chest,54,0 +container,54,0 +diamondore,56,0 +crystalore,56,0 +orediamond,56,0 +orecrystal,56,0 +dore,56,0 +ored,56,0 +diamondblock,57,0 +blockdiamond,57,0 +crystalblock,57,0 +blockcrystal,57,0 +dblock,57,0 +blockd,57,0 +workbench,58,0 +craftingbench,58,0 +crafterbench,58,0 +craftbench,58,0 +worktable,58,0 +craftingtable,58,0 +craftertable,58,0 +crafttable,58,0 +wbench,58,0 +cbench,58,0 +soil,60,0 +furnace,61,0 +litfurnace,62,0 +lfurnace,62,0 +burningfurnace,62,0 +burnfurnace,62,0 +bfurnace,62,0 +ladder,65,0 +minecarttrack,66,0 +minecartrails,66,0 +minecartrail,66,0 +mcarttrack,66,0 +mcartrails,66,0 +mcartrail,66,0 +mctrack,66,0 +mcrails,66,0 +mcrail,66,0 +track,66,0 +rails,66,0 +rail,66,0 +cobblestonestairs,67,0 +cstonestairs,67,0 +stonestairs,67,0 +cobblestairs,67,0 +csstairs,67,0 +sstairs,67,0 +cstairs,67,0 +cobblestonestair,67,0 +cstonestair,67,0 +stonestair,67,0 +cobblestair,67,0 +csstair,67,0 +sstair,67,0 +cstair,67,0 +lever,69,0 +stonepressureplate,70,0 +stonepressplate,70,0 +stonepplate,70,0 +stoneplate,70,0 +spressureplate,70,0 +spressplate,70,0 +spplate,70,0 +splate,70,0 +smoothstonepressureplate,70,0 +smoothstonepressplate,70,0 +smoothstonepplate,70,0 +smoothstoneplate,70,0 +sstonepressureplate,70,0 +sstonepressplate,70,0 +sstonepplate,70,0 +sstoneplate,70,0 +woodenpressureplate,72,0 +woodenpressplate,72,0 +woodenpplate,72,0 +woodenplate,72,0 +woodpressureplate,72,0 +woodpressplate,72,0 +woodpplate,72,0 +woodplate,72,0 +wpressureplate,72,0 +wpressplate,72,0 +wpplate,72,0 +wplate,72,0 +redstoneore,73,0 +redsore,73,0 +redore,73,0 +rstoneore,73,0 +rsore,73,0 +rore,73,0 +oreredstone,73,0 +orereds,73,0 +orered,73,0 +orerstone,73,0 +orers,73,0 +orer,73,0 +redstonetorch,76,0 +rstonetorch,76,0 +redstorch,76,0 +redtorch,76,0 +rstorch,76,0 +stonebutton,77,0 +smoothstonebutton,77,0 +sstonebutton,77,0 +sbutton,77,0 +button,77,0 +snowcover,78,0 +snowcovering,78,0 +scover,78,0 +ice,79,0 +frozenwater,79,0 +waterfrozen,79,0 +freezewater,79,0 +waterfreeze,79,0 +snowblock,80,0 +blocksnow,80,0 +sblock,80,0 +blocks,80,0 +cactus,81,0 +cactuses,81,0 +cacti,81,0 +clayblock,82,0 +blockclay,82,0 +cblock,82,0 +blockc,82,0 +jukebox,84,0 +jbox,84,0 +woodenfence,85,0 +fence,85,0 +woodfence,85,0 +wfence,85,0 +fencewooden,85,0 +fencewood,85,0 +fencew,85,0 +pumpkin,86,0 +netherrack,87,0 +netherrock,87,0 +netherstone,87,0 +hellrack,87,0 +hellrock,87,0 +hellstone,87,0 +deathrack,87,0 +deathrock,87,0 +deathstone,87,0 +nrack,87,0 +nrock,87,0 +nstone,87,0 +hrack,87,0 +hrock,87,0 +hstone,87,0 +drack,87,0 +drock,87,0 +dstone,87,0 +soulsand,88,0 +slowsand,88,0 +slowmud,88,0 +ssand,88,0 +smud,88,0 +mud,88,0 +glowstone,89,0 +glowingstoneblock,89,0 +lightstoneblock,89,0 +glowstoneblock,89,0 +blockglowingstone,89,0 +blocklightstone,89,0 +blockglowstone,89,0 +glowingstone,89,0 +lightstone,89,0 +glowingblock,89,0 +lightblock,89,0 +glowblock,89,0 +lstone,89,0 +gstone,89,0 +portal,90,0 +jackolantern,91,0 +pumpkinlantern,91,0 +glowingpumpkin,91,0 +lightpumpkin,91,0 +jpumpkin,91,0 +plantren,91,0 +glowpumpkin,91,0 +gpumpkin,91,0 +lpumpkin,91,0 +lockedchest,95,0 +lockchest,95,0 +jokechest,95,0 +whiteglass,95,0 +whitesglass,95,0 +whitestainedglass,95,0 +wglass,95,0 +wsglass,95,0 +wstainedglass,95,0 +sglass,95,0 +stainedglass,95,0 +orangeglass,95,1 +orangesglass,95,1 +orangestainedglass,95,1 +oglass,95,1 +osglass,95,1 +ostainedglass,95,1 +magentaglass,95,2 +magentasglass,95,2 +magentastainedglass,95,2 +mglass,95,2 +msglass,95,2 +mstainedglass,95,2 +lightblueglass,95,3 +lightbluesglass,95,3 +lightbluestainedglass,95,3 +lblueglass,95,3 +lbluesglass,95,3 +lbluestainedglass,95,3 +lightbluglass,95,3 +lightblusglass,95,3 +lightblustainedglass,95,3 +lbluglass,95,3 +lblusglass,95,3 +lblustainedglass,95,3 +lbglass,95,3 +lbsglass,95,3 +lbstainedglass,95,3 +yellowglass,95,4 +yellowsglass,95,4 +yellowstainedglass,95,4 +yglass,95,4 +ysglass,95,4 +ystainedglass,95,4 +lightgreenglass,95,5 +lightgreensglass,95,5 +lightgreenstainedglass,95,5 +lgreenglass,95,5 +lgreensglass,95,5 +lgreenstainedglass,95,5 +lightgreglass,95,5 +lightgresglass,95,5 +lightgrestainedglass,95,5 +lgreglass,95,5 +lgresglass,95,5 +lgrestainedglass,95,5 +limeglass,95,5 +limesglass,95,5 +limestainedglass,95,5 +lglass,95,5 +lsglass,95,5 +lstainedglass,95,5 +pinkglass,95,6 +pinksglass,95,6 +pinkstainedglass,95,6 +piglass,95,6 +pisglass,95,6 +pistainedglass,95,6 +darkgrayglass,95,7 +darkgraysglass,95,7 +darkgraystainedglass,95,7 +dgrayglass,95,7 +dgraysglass,95,7 +dgraystainedglass,95,7 +darkgreyglass,95,7 +darkgreysglass,95,7 +darkgreystainedglass,95,7 +dgreyglass,95,7 +dgreysglass,95,7 +dgreystainedglass,95,7 +darkgraglass,95,7 +darkgrasglass,95,7 +darkgrastainedglass,95,7 +dgraglass,95,7 +dgrasglass,95,7 +dgrastainedglass,95,7 +grayglass,95,7 +graysglass,95,7 +graystainedglass,95,7 +greyglass,95,7 +greysglass,95,7 +greystainedglass,95,7 +graglass,95,7 +grasglass,95,7 +grastainedglass,95,7 +lightgrayglass,95,8 +lightgraysglass,95,8 +lightgraystainedglass,95,8 +lgrayglass,95,8 +lgraysglass,95,8 +lgraystainedglass,95,8 +lightgreyglass,95,8 +lightgreysglass,95,8 +lightgreystainedglass,95,8 +lgreyglass,95,8 +lgreysglass,95,8 +lgreystainedglass,95,8 +lightgraglass,95,8 +lightgrasglass,95,8 +lightgrastainedglass,95,8 +lgraglass,95,8 +lgrasglass,95,8 +lgrastainedglass,95,8 +silverglass,95,8 +silversglass,95,8 +silverstainedglass,95,8 +siglass,95,8 +siasglass,95,8 +siastainedglass,95,8 +cyanglass,95,9 +cyansglass,95,9 +cyanstainedglass,95,9 +cglass,95,9 +csglass,95,9 +cstainedglass,95,9 +purpleglass,95,10 +purplesglass,95,10 +purplestainedglass,95,10 +puglass,95,10 +pusglass,95,10 +pustainedglass,95,10 +blueglass,95,11 +bluesglass,95,11 +bluestainedglass,95,11 +bluglass,95,11 +blusglass,95,11 +blustainedglass,95,11 +brownglass,95,12 +brownsglass,95,12 +brownstainedglass,95,12 +broglass,95,12 +brosglass,95,12 +brostainedglass,95,12 +darkgreenglass,95,13 +darkgreensglass,95,13 +darkgreenstainedglass,95,13 +dgreenglass,95,13 +dgreensglass,95,13 +dgreenstainedglass,95,13 +greenglass,95,13 +greensglass,95,13 +greenstainedglass,95,13 +darkgreglass,95,13 +darkgresglass,95,13 +darkgrestainedglass,95,13 +dgreglass,95,13 +dgresglass,95,13 +dgrestainedglass,95,13 +greglass,95,13 +gresglass,95,13 +grestainedglass,95,13 +redglass,95,14 +redsglass,95,14 +redstainedglass,95,14 +rglass,95,14 +rsglass,95,14 +rstainedglass,95,14 +blackglass,95,15 +blacksglass,95,15 +blackstainedglass,95,15 +blaglass,95,15 +blasglass,95,15 +blastainedglass,95,15 +trapdoor,96,0 +doortrap,96,0 +hatch,96,0 +tdoor,96,0 +doort,96,0 +trapd,96,0 +dtrap,96,0 +silverfish,97,0 +silverfishsmoothstone,97,0 +silverfishsstone,97,0 +sfishsmoothstone,97,0 +sfishsstone,97,0 +fishsmoothstone,97,0 +fishsstone,97,0 +sfsmoothstone,97,0 +sfsstone,97,0 +trapsmoothstone,97,0 +trapsstone,97,0 +monsteregg,97,0 +monstereggsmoothstone,97,0 +monstereggsstone,97,0 +meggsmoothstone,97,0 +meggsstone,97,0 +mesmoothstone,97,0 +messtone,97,0 +silverfishcobblestone,97,1 +silverfishcstone,97,1 +sfishcobblestone,97,1 +sfishcstone,97,1 +fishcobblestone,97,1 +fishcstone,97,1 +sfcobblestone,97,1 +sfcstone,97,1 +trapcobblestone,97,1 +trapcstone,97,1 +monstereggcobblestone,97,1 +monstereggcstone,97,1 +meggcobblestone,97,1 +meggcstone,97,1 +mecobblestone,97,1 +mecstone,97,1 +silverfishstonebrick,97,2 +silverfishsbrick,97,2 +sfishstonebrick,97,2 +sfishsbrick,97,2 +fishstonebrick,97,2 +fishsbrick,97,2 +sfstonebrick,97,2 +sfsbrick,97,2 +trapstonebrick,97,2 +trapsbrick,97,2 +monstereggstonebrick,97,2 +monstereggsbrick,97,2 +meggstonebrick,97,2 +meggsbrick,97,2 +mestonebrick,97,2 +mesbrick,97,2 +silverfishmossystonebrick,97,3 +silverfishmossstonebrick,97,3 +silverfishmstonebrick,97,3 +silverfishmsbrick,97,3 +sfishmossystonebrick,97,3 +sfishmossstonebrick,97,3 +sfishmstonebrick,97,3 +sfishmsbrick,97,3 +fishmossystonebrick,97,3 +fishmossstonebrick,97,3 +fishmstonebrick,97,3 +fishmsbrick,97,3 +sfmossystonebrick,97,3 +sfmossstonebrick,97,3 +sfmstonebrick,97,3 +sfmsbrick,97,3 +trapmossystonebrick,97,3 +trapmossstonebrick,97,3 +trapmstonebrick,97,3 +trapmsbrick,97,3 +monstereggmossystonebrick,97,3 +monstereggmossstonebrick,97,3 +monstereggmstonebrick,97,3 +monstereggmsbrick,97,3 +meggmossystonebrick,97,3 +meggmossstonebrick,97,3 +meggmstonebrick,97,3 +meggmsbrick,97,3 +memossystonebrick,97,3 +memossstonebrick,97,3 +memstonebrick,97,3 +memsbrick,97,3 +silverfishcrackedstonebrick,97,4 +silverfishcrackstonebrick,97,4 +silverfishcrstonebrick,97,4 +silverfishcrsbrick,97,4 +sfishcrackedstonebrick,97,4 +sfishcrackstonebrick,97,4 +sfishcrstonebrick,97,4 +sfishcrsbrick,97,4 +fishcrackedstonebrick,97,4 +fishcrackstonebrick,97,4 +fishcrstonebrick,97,4 +fishcrsbrick,97,4 +sfcrackedstonebrick,97,4 +sfcrackstonebrick,97,4 +sfcrstonebrick,97,4 +sfcrsbrick,97,4 +trapcrackedstonebrick,97,4 +trapcrackstonebrick,97,4 +trapcrstonebrick,97,4 +trapcrsbrick,97,4 +monstereggcrackedstonebrick,97,4 +monstereggcrackstonebrick,97,4 +monstereggcrstonebrick,97,4 +monstereggcrsbrick,97,4 +meggcrackedstonebrick,97,4 +meggcrackstonebrick,97,4 +meggcrstonebrick,97,4 +meggcrsbrick,97,4 +mecrackedstonebrick,97,4 +mecrackstonebrick,97,4 +mecrstonebrick,97,4 +mecrsbrick,97,4 +silverfishcirclestonebrick,97,5 +silverfishcistonebrick,97,5 +silverfishcisbrick,97,5 +sfishcirclestonebrick,97,5 +sfishcistonebrick,97,5 +sfishcisbrick,97,5 +fishcirclestonebrick,97,5 +fishcistonebrick,97,5 +fishcisbrick,97,5 +sfcirclestonebrick,97,5 +sfcistonebrick,97,5 +sfcisbrick,97,5 +trapcirclestonebrick,97,5 +trapcistonebrick,97,5 +trapcisbrick,97,5 +monstereggcirclestonebrick,97,5 +monstereggcistonebrick,97,5 +monstereggcisbrick,97,5 +meggcirclestonebrick,97,5 +meggcistonebrick,97,5 +meggcisbrick,97,5 +mecirclestonebrick,97,5 +mecistonebrick,97,5 +mecisbrick,97,5 +stonebrick,98,0 +stonebricks,98,0 +stonebrickblock,98,0 +stonebb,98,0 +sbrick,98,0 +mossystonebrick,98,1 +mossystonebricks,98,1 +mossystonebrickblock,98,1 +mossystonebb,98,1 +mossstonebrick,98,1 +mossstonebricks,98,1 +mossstonebrickblock,98,1 +mossstonebb,98,1 +mstonebrick,98,1 +mstonebricks,98,1 +mstonebrickblock,98,1 +mstonebb,98,1 +mosssbrick,98,1 +mosssbricks,98,1 +mosssbrickblock,98,1 +mosssbb,98,1 +msbrick,98,1 +msbricks,98,1 +msbrickblock,98,1 +crackedstone,98,2 +crackedstonebrick,98,2 +crackedstonebricks,98,2 +crackedstonebrickblock,98,2 +crackedstonebb,98,2 +crackstonebrick,98,2 +crackstonebricks,98,2 +crackstonebrickblock,98,2 +crackstonebb,98,2 +crstonebrick,98,2 +crstonebricks,98,2 +crstonebrickblock,98,2 +crstonebb,98,2 +cracksbrick,98,2 +cracksbricks,98,2 +cracksbrickblock,98,2 +cracksbb,98,2 +crsbrick,98,2 +crsbricks,98,2 +crsbrickblock,98,2 +circlestone,98,3 +circlestonebrick,98,3 +circlestonebricks,98,3 +circlestonebrickblock,98,3 +circlestonebb,98,3 +cistonebrick,98,3 +cistonebricks,98,3 +cistonebrickblock,98,3 +cistonebb,98,3 +circlesbrick,98,3 +circlesbricks,98,3 +circlesbrickblock,98,3 +circlesbb,98,3 +cisbrick,98,3 +cisbricks,98,3 +cisbrickblock,98,3 +giantredmushroom,99,0 +hugeredmushroom,99,0 +bigredmushroom,99,0 +gredmushroom,99,0 +hredmushroom,99,0 +bredmushroom,99,0 +giantrmushroom,99,0 +hugermushroom,99,0 +bigrmushroom,99,0 +grmushroom,99,0 +hrmushroom,99,0 +brmushroom,99,0 +giantredmush,99,0 +hugeredmush,99,0 +bigredmush,99,0 +gredmush,99,0 +hredmush,99,0 +bredmush,99,0 +giantrmush,99,0 +hugermush,99,0 +bigrmush,99,0 +grmush,99,0 +hrmush,99,0 +brmush,99,0 +giantbrownmushroom,100,0 +hugebrownmushroom,100,0 +bigbrownmushroom,100,0 +gbrownmushroom,100,0 +hbrownmushroom,100,0 +bbrownmushroom,100,0 +giantbmushroom,100,0 +hugebmushroom,100,0 +bigbmushroom,100,0 +gbmushroom,100,0 +hbmushroom,100,0 +bbmushroom,100,0 +giantbrownmush,100,0 +hugebrownmush,100,0 +bigbrownmush,100,0 +gbrownmush,100,0 +hbrownmush,100,0 +bbrownmush,100,0 +giantbmush,100,0 +hugebmush,100,0 +bigbmush,100,0 +gbmush,100,0 +hbmush,100,0 +bbmush,100,0 +ironbars,101,0 +ironbarsb,101,0 +ironbarsblock,101,0 +ironfence,101,0 +metalbars,101,0 +metalbarsb,101,0 +metalbarsblock,101,0 +metalfence,101,0 +jailbars,101,0 +jailbarsb,101,0 +jailbarsblock,101,0 +jailfence,101,0 +mbars,101,0 +mbarsb,101,0 +mbarsblock,101,0 +mfence,101,0 +jbars,101,0 +jbarsb,101,0 +jbarsblock,101,0 +jfence,101,0 +ibars,101,0 +ibarsb,101,0 +ibarsblock,101,0 +ifence,101,0 +glasspane,102,0 +glassp,102,0 +paneglass,102,0 +pglass,102,0 +flatglass,102,0 +fglass,102,0 +skinnyglass,102,0 +glassflat,102,0 +glassf,102,0 +glassskinny,102,0 +glasss,102,0 +melon,103,0 +watermelon,103,0 +greenmelon,103,0 +melongreen,103,0 +melonblock,103,0 +watermelonblock,103,0 +greenmelonblock,103,0 +vines,106,0 +vine,106,0 +greenvines,106,0 +greenvine,106,0 +gardenvines,106,0 +gardenvine,106,0 +vinesgreen,106,0 +vinegreen,106,0 +vinesgarden,106,0 +vinegarden,106,0 +vinesg,106,0 +vineg,106,0 +gvines,106,0 +gvine,106,0 +woodgate,107,0 +woodenfencegate,107,0 +wfencegate,107,0 +woodfencegate,107,0 +woodengate,107,0 +wgate,107,0 +gate,107,0 +gardengate,107,0 +ggate,107,0 +fencegate,107,0 +fgate,107,0 +brickstairs,108,0 +redbrickstairs,108,0 +redbstairs,108,0 +rbrickstairs,108,0 +bstairs,108,0 +redstairs,108,0 +brickstair,108,0 +redbrickstair,108,0 +redbstair,108,0 +rbrickstair,108,0 +bstair,108,0 +redstair,108,0 +stonebrickstairs,109,0 +stonebstairs,109,0 +sbstairs,109,0 +cementbrickstairs,109,0 +cementstairs,109,0 +cementbstairs,109,0 +cbstairs,109,0 +greybrickstairs,109,0 +greybstairs,109,0 +greystairs,109,0 +mycelium,110,0 +purplegrass,110,0 +pinkgrass,110,0 +mycel,110,0 +swampgrass,110,0 +sgrass,110,0 +mushroomgrass,110,0 +mushgrass,110,0 +lilypad,111,0 +waterlily,111,0 +lily,111,0 +swamppad,111,0 +lpad,111,0 +wlily,111,0 +netherbrickblock,112,0 +hellbrickblock,112,0 +deathbrickblock,112,0 +nbrickblock,112,0 +hbrickblock,112,0 +dbrickblock,112,0 +netherbblock,112,0 +hellbblock,112,0 +deathbblock,112,0 +nbblock,112,0 +hbblock,112,0 +dbblock,112,0 +netherbrickfence,113,0 +hellbrickfence,113,0 +nbrickfence,113,0 +hbrickfence,113,0 +netherbfence,113,0 +hellbfence,113,0 +netherfence,113,0 +hellfence,113,0 +nbfence,113,0 +hbfence,113,0 +nfence,113,0 +hfence,113,0 +netherbrickstairs,114,0 +hellbrickstairs,114,0 +nbrickstairs,114,0 +hbrickstairs,114,0 +netherbstairs,114,0 +hellbstairs,114,0 +netherstairs,114,0 +hellstairs,114,0 +nbstairs,114,0 +hbstairs,114,0 +nstairs,114,0 +hstairs,114,0 +netherbrickstair,114,0 +hellbrickstair,114,0 +nbrickstair,114,0 +hbrickstair,114,0 +netherbstair,114,0 +hellbstair,114,0 +netherstair,114,0 +hellstair,114,0 +nbstair,114,0 +hbstair,114,0 +nstair,114,0 +hstair,114,0 +enchantmenttable,116,0 +enchantingtable,116,0 +enchanttable,116,0 +etable,116,0 +magicaltable,116,0 +magictable,116,0 +mtable,116,0 +enchantmentdesk,116,0 +enchantingdesk,116,0 +enchantdesk,116,0 +edesk,116,0 +magicaldesk,116,0 +magicdesk,116,0 +mdesk,116,0 +booktable,116,0 +bookdesk,116,0 +btable,116,0 +bdesk,116,0 +enderportal,119,0 +endergoo,119,0 +endgoo,119,0 +endportal,119,0 +egoo,119,0 +eportal,119,0 +enderportalframe,120,0 +endportalframe,120,0 +endgooframe,120,0 +endergooframe,120,0 +egooframe,120,0 +eportalframe,120,0 +enderframe,120,0 +endframe,120,0 +enderstone,121,0 +endstone,121,0 +endrock,121,0 +enderrock,121,0 +erock,121,0 +estone,121,0 +enderdragonegg,122,0 +endegg,122,0 +dragonegg,122,0 +degg,122,0 +bossegg,122,0 +begg,122,0 +redstonelamp,123,0 +redlamp,123,0 +rslamp,123,0 +woodendoublestep,125,0 +woodendstep,125,0 +wooddoublestep,125,0 +wooddstep,125,0 +wdoublestep,125,0 +wdstep,125,0 +doublewoodenstep,125,0 +dwoodenstep,125,0 +doublewoodstep,125,0 +dwoodstep,125,0 +doublewstep,125,0 +dwstep,125,0 +woodendoubleslab,125,0 +woodendslab,125,0 +wooddoubleslab,125,0 +wooddslab,125,0 +wdoubleslab,125,0 +wdslab,125,0 +doublewoodenslab,125,0 +dwoodenslab,125,0 +doublewoodslab,125,0 +dwoodslab,125,0 +doublewslab,125,0 +dwslab,125,0 +woodendoublehalfblock,125,0 +woodendhalfblock,125,0 +wooddoublehalfblock,125,0 +wooddhalfblock,125,0 +wdoublehalfblock,125,0 +wdhalfblock,125,0 +doublewoodenhalfblock,125,0 +dwoodenhalfblock,125,0 +doublewoodhalfblock,125,0 +dwoodhalfblock,125,0 +doublewhalfblock,125,0 +dwhalfblock,125,0 +oakwoodendoublehalfblock,125,0 +oakwoodendhalfblock,125,0 +oakwooddoublehalfblock,125,0 +oakwooddhalfblock,125,0 +oakwdoublehalfblock,125,0 +oakwdhalfblock,125,0 +oakdoublewoodenhalfblock,125,0 +oakdwoodenhalfblock,125,0 +oakdoublewoodhalfblock,125,0 +oakdwoodhalfblock,125,0 +oakdoublewhalfblock,125,0 +oakdwhalfblock,125,0 +oakdoublehalfblock,125,0 +oakdhalfblock,125,0 +odhalfblock,125,0 +oakwoodendoublestep,125,0 +oakwoodendstep,125,0 +oakwooddoublestep,125,0 +oakwooddstep,125,0 +oakwdoublestep,125,0 +oakwdstep,125,0 +oakdoublewoodenstep,125,0 +oakdwoodenstep,125,0 +oakdoublewoodstep,125,0 +oakdwoodstep,125,0 +oakdoublewstep,125,0 +oakdwstep,125,0 +oakdoublestep,125,0 +oakdstep,125,0 +odstep,125,0 +oakwoodendoubleslab,125,0 +oakwoodendslab,125,0 +oakwooddoubleslab,125,0 +oakwooddslab,125,0 +oakwdoubleslab,125,0 +oakwdslab,125,0 +oakdoublewoodenslab,125,0 +oakdwoodenslab,125,0 +oakdoublewoodslab,125,0 +oakdwoodslab,125,0 +oakdoublewslab,125,0 +oakdwslab,125,0 +oakdoubleslab,125,0 +oakdslab,125,0 +odslab,125,0 +sprucewoodendoublestep,125,1 +sprucewoodendstep,125,1 +sprucewooddoublestep,125,1 +sprucewooddstep,125,1 +sprucewdoublestep,125,1 +sprucewdstep,125,1 +sprucedoublewoodenstep,125,1 +sprucedwoodenstep,125,1 +sprucedoublewoodstep,125,1 +sprucedwoodstep,125,1 +sprucedoublewstep,125,1 +sprucedwstep,125,1 +sprucedoublestep,125,1 +sprucedstep,125,1 +sprucewoodendoubleslab,125,1 +sprucewoodendslab,125,1 +sprucewooddoubleslab,125,1 +sprucewooddslab,125,1 +sprucewdoubleslab,125,1 +sprucewdslab,125,1 +sprucedoublewoodenslab,125,1 +sprucedwoodenslab,125,1 +sprucedoublewoodslab,125,1 +sprucedwoodslab,125,1 +sprucedoublewslab,125,1 +sprucedwslab,125,1 +sprucedoubleslab,125,1 +sprucedslab,125,1 +sprucewoodendoublehalfblock,125,1 +sprucewoodendhalfblock,125,1 +sprucewooddoublehalfblock,125,1 +sprucewooddhalfblock,125,1 +sprucewdoublehalfblock,125,1 +sprucewdhalfblock,125,1 +sprucedoublewoodenhalfblock,125,1 +sprucedwoodenhalfblock,125,1 +sprucedoublewoodhalfblock,125,1 +sprucedwoodhalfblock,125,1 +sprucedoublewhalfblock,125,1 +sprucedwhalfblock,125,1 +sprucedoublehalfblock,125,1 +sprucedhalfblock,125,1 +darkwoodendoublestep,125,1 +darkwoodendstep,125,1 +darkwooddoublestep,125,1 +darkwooddstep,125,1 +darkwdoublestep,125,1 +darkwdstep,125,1 +darkdoublewoodenstep,125,1 +darkdwoodenstep,125,1 +darkdoublewoodstep,125,1 +darkdwoodstep,125,1 +darkdoublewstep,125,1 +darkdwstep,125,1 +darkdoublestep,125,1 +darkdstep,125,1 +ddstep,125,1 +darkwoodendoubleslab,125,1 +darkwoodendslab,125,1 +darkwooddoubleslab,125,1 +darkwooddslab,125,1 +darkwdoubleslab,125,1 +darkwdslab,125,1 +darkdoublewoodenslab,125,1 +darkdwoodenslab,125,1 +darkdoublewoodslab,125,1 +darkdwoodslab,125,1 +darkdoublewslab,125,1 +darkdwslab,125,1 +darkdoubleslab,125,1 +darkdslab,125,1 +ddslab,125,1 +darkwoodendoublehalfblock,125,1 +darkwoodendhalfblock,125,1 +darkwooddoublehalfblock,125,1 +darkwooddhalfblock,125,1 +darkwdoublehalfblock,125,1 +darkwdhalfblock,125,1 +darkdoublewoodenhalfblock,125,1 +darkdwoodenhalfblock,125,1 +darkdoublewoodhalfblock,125,1 +darkdwoodhalfblock,125,1 +darkdoublewhalfblock,125,1 +darkdwhalfblock,125,1 +darkdoublehalfblock,125,1 +darkdhalfblock,125,1 +ddhalfblock,125,1 +birchwoodendoublestep,125,2 +birchwoodendstep,125,2 +birchwooddoublestep,125,2 +birchwooddstep,125,2 +birchwdoublestep,125,2 +birchwdstep,125,2 +birchdoublewoodenstep,125,2 +birchdwoodenstep,125,2 +birchdoublewoodstep,125,2 +birchdwoodstep,125,2 +birchdoublewstep,125,2 +birchdwstep,125,2 +birchdoublestep,125,2 +birchdstep,125,2 +birchwoodendoubleslab,125,2 +birchwoodendslab,125,2 +birchwooddoubleslab,125,2 +birchwooddslab,125,2 +birchwdoubleslab,125,2 +birchwdslab,125,2 +birchdoublewoodenslab,125,2 +birchdwoodenslab,125,2 +birchdoublewoodslab,125,2 +birchdwoodslab,125,2 +birchdoublewslab,125,2 +birchdwslab,125,2 +birchdoubleslab,125,2 +birchdslab,125,2 +birchwoodendoublehalfblock,125,2 +birchwoodendhalfblock,125,2 +birchwooddoublehalfblock,125,2 +birchwooddhalfblock,125,2 +birchwdoublehalfblock,125,2 +birchwdhalfblock,125,2 +birchdoublewoodenhalfblock,125,2 +birchdwoodenhalfblock,125,2 +birchdoublewoodhalfblock,125,2 +birchdwoodhalfblock,125,2 +birchdoublewhalfblock,125,2 +birchdwhalfblock,125,2 +birchdoublehalfblock,125,2 +birchdhalfblock,125,2 +lightwoodendoublehalfblock,125,2 +lightwoodendhalfblock,125,2 +lightwooddoublehalfblock,125,2 +lightwooddhalfblock,125,2 +lightwdoublehalfblock,125,2 +lightwdhalfblock,125,2 +lightdoublewoodenhalfblock,125,2 +lightdwoodenhalfblock,125,2 +lightdoublewoodhalfblock,125,2 +lightdwoodhalfblock,125,2 +lightdoublewhalfblock,125,2 +lightdwhalfblock,125,2 +lightdoublehalfblock,125,2 +lightdhalfblock,125,2 +ldhalfblock,125,2 +lightwoodendoublestep,125,2 +lightwoodendstep,125,2 +lightwooddoublestep,125,2 +lightwooddstep,125,2 +lightwdoublestep,125,2 +lightwdstep,125,2 +lightdoublewoodenstep,125,2 +lightdwoodenstep,125,2 +lightdoublewoodstep,125,2 +lightdwoodstep,125,2 +lightdoublewstep,125,2 +lightdwstep,125,2 +lightdoublestep,125,2 +lightdstep,125,2 +ldstep,125,2 +lightwoodendoubleslab,125,2 +lightwoodendslab,125,2 +lightwooddoubleslab,125,2 +lightwooddslab,125,2 +lightwdoubleslab,125,2 +lightwdslab,125,2 +lightdoublewoodenslab,125,2 +lightdwoodenslab,125,2 +lightdoublewoodslab,125,2 +lightdwoodslab,125,2 +lightdoublewslab,125,2 +lightdwslab,125,2 +lightdoubleslab,125,2 +lightdslab,125,2 +ldslab,125,2 +junglewoodendoublestep,125,3 +junglewoodendstep,125,3 +junglewooddoublestep,125,3 +junglewooddstep,125,3 +junglewdoublestep,125,3 +junglewdstep,125,3 +jungledoublewoodenstep,125,3 +jungledwoodenstep,125,3 +jungledoublewoodstep,125,3 +jungledwoodstep,125,3 +jungledoublewstep,125,3 +jungledwstep,125,3 +jungledoublestep,125,3 +jungledstep,125,3 +jdstep,125,3 +junglewoodendoubleslab,125,3 +junglewoodendslab,125,3 +junglewooddoubleslab,125,3 +junglewooddslab,125,3 +junglewdoubleslab,125,3 +junglewdslab,125,3 +jungledoublewoodenslab,125,3 +jungledwoodenslab,125,3 +jungledoublewoodslab,125,3 +jungledwoodslab,125,3 +jungledoublewslab,125,3 +jungledwslab,125,3 +jungledoubleslab,125,3 +jungledslab,125,3 +jdslab,125,3 +junglewoodendoublehalfblock,125,3 +junglewoodendhalfblock,125,3 +junglewooddoublehalfblock,125,3 +junglewooddhalfblock,125,3 +junglewdoublehalfblock,125,3 +junglewdhalfblock,125,3 +jungledoublewoodenhalfblock,125,3 +jungledwoodenhalfblock,125,3 +jungledoublewoodhalfblock,125,3 +jungledwoodhalfblock,125,3 +jungledoublewhalfblock,125,3 +jungledwhalfblock,125,3 +jungledoublehalfblock,125,3 +jungledhalfblock,125,3 +jdhalfblock,125,3 +forestwoodendoublehalfblock,125,3 +forestwoodendhalfblock,125,3 +forestwooddoublehalfblock,125,3 +forestwooddhalfblock,125,3 +forestwdoublehalfblock,125,3 +forestwdhalfblock,125,3 +forestdoublewoodenhalfblock,125,3 +forestdwoodenhalfblock,125,3 +forestdoublewoodhalfblock,125,3 +forestdwoodhalfblock,125,3 +forestdoublewhalfblock,125,3 +forestdwhalfblock,125,3 +forestdoublehalfblock,125,3 +forestdhalfblock,125,3 +fdhalfblock,125,3 +forestwoodendoublestep,125,3 +forestwoodendstep,125,3 +forestwooddoublestep,125,3 +forestwooddstep,125,3 +forestwdoublestep,125,3 +forestwdstep,125,3 +forestdoublewoodenstep,125,3 +forestdwoodenstep,125,3 +forestdoublewoodstep,125,3 +forestdwoodstep,125,3 +forestdoublewstep,125,3 +forestdwstep,125,3 +forestdoublestep,125,3 +forestdstep,125,3 +fdstep,125,3 +forestwoodendoubleslab,125,3 +forestwoodendslab,125,3 +forestwooddoubleslab,125,3 +forestwooddslab,125,3 +forestwdoubleslab,125,3 +forestwdslab,125,3 +forestdoublewoodenslab,125,3 +forestdwoodenslab,125,3 +forestdoublewoodslab,125,3 +forestdwoodslab,125,3 +forestdoublewslab,125,3 +forestdwslab,125,3 +forestdoubleslab,125,3 +forestdslab,125,3 +fdslab,125,3 +acaciawoodendoublestep,125,4 +acaciawoodendstep,125,4 +acaciawooddoublestep,125,4 +acaciawooddstep,125,4 +acaciawdoublestep,125,4 +acaciawdstep,125,4 +acaciadoublewoodenstep,125,4 +acaciadwoodenstep,125,4 +acaciadoublewoodstep,125,4 +acaciadwoodstep,125,4 +acaciadoublewstep,125,4 +acaciadwstep,125,4 +acaciadoublestep,125,4 +acaciadstep,125,4 +adstep,125,4 +acaciawoodendoubleslab,125,4 +acaciawoodendslab,125,4 +acaciawooddoubleslab,125,4 +acaciawooddslab,125,4 +acaciawdoubleslab,125,4 +acaciawdslab,125,4 +acaciadoublewoodenslab,125,4 +acaciadwoodenslab,125,4 +acaciadoublewoodslab,125,4 +acaciadwoodslab,125,4 +acaciadoublewslab,125,4 +acaciadwslab,125,4 +acaciadoubleslab,125,4 +acaciadslab,125,4 +adslab,125,4 +acaciawoodendoublehalfblock,125,4 +acaciawoodendhalfblock,125,4 +acaciawooddoublehalfblock,125,4 +acaciawooddhalfblock,125,4 +acaciawdoublehalfblock,125,4 +acaciawdhalfblock,125,4 +acaciadoublewoodenhalfblock,125,4 +acaciadwoodenhalfblock,125,4 +acaciadoublewoodhalfblock,125,4 +acaciadwoodhalfblock,125,4 +acaciadoublewhalfblock,125,4 +acaciadwhalfblock,125,4 +acaciadoublehalfblock,125,4 +acaciadhalfblock,125,4 +adhalfblock,125,4 +darkoakwoodendoublehalfblock,125,5 +darkoakwoodendhalfblock,125,5 +darkoakwooddoublehalfblock,125,5 +darkoakwooddhalfblock,125,5 +darkoakwdoublehalfblock,125,5 +darkoakwdhalfblock,125,5 +darkoakdoublewoodenhalfblock,125,5 +darkoakdwoodenhalfblock,125,5 +darkoakdoublewoodhalfblock,125,5 +darkoakdwoodhalfblock,125,5 +darkoakdoublewhalfblock,125,5 +darkoakdwhalfblock,125,5 +darkoakdoublehalfblock,125,5 +darkoakdhalfblock,125,5 +dodhalfblock,125,5 +darkoakwoodendoublestep,125,5 +darkoakwoodendstep,125,5 +darkoakwooddoublestep,125,5 +darkoakwooddstep,125,5 +darkoakwdoublestep,125,5 +darkoakwdstep,125,5 +darkoakdoublewoodenstep,125,5 +darkoakdwoodenstep,125,5 +darkoakdoublewoodstep,125,5 +darkoakdwoodstep,125,5 +darkoakdoublewstep,125,5 +darkoakdwstep,125,5 +darkoakdoublestep,125,5 +darkoakdstep,125,5 +dodstep,125,5 +darkoakwoodendoubleslab,125,5 +darkoakwoodendslab,125,5 +darkoakwooddoubleslab,125,5 +darkoakwooddslab,125,5 +darkoakwdoubleslab,125,5 +darkoakwdslab,125,5 +darkoakdoublewoodenslab,125,5 +darkoakdwoodenslab,125,5 +darkoakdoublewoodslab,125,5 +darkoakdwoodslab,125,5 +darkoakdoublewslab,125,5 +darkoakdwslab,125,5 +darkoakdoubleslab,125,5 +darkoakdslab,125,5 +dodslab,125,5 +woodenstep,126,0 +woodstep,126,0 +wstep,126,0 +woodenslab,126,0 +woodslab,126,0 +wslab,126,0 +woodenhalfblock,126,0 +woodhalfblock,126,0 +whalfblock,126,0 +oakwoodenstep,126,0 +oakwoodstep,126,0 +oakwstep,126,0 +oakstep,126,0 +ostep,126,0 +oakwoodenslab,126,0 +oakwoodslab,126,0 +oakwslab,126,0 +oakslab,126,0 +oslab,126,0 +oakwoodenhalfblock,126,0 +oakwoodhalfblock,126,0 +oakwhalfblock,126,0 +oakhalfblock,126,0 +ohalfblock,126,0 +sprucewoodenstep,126,1 +sprucewoodstep,126,1 +sprucewstep,126,1 +sprucestep,126,1 +sprucewoodenslab,126,1 +sprucewoodslab,126,1 +sprucewslab,126,1 +spruceslab,126,1 +sprucewoodenhalfblock,126,1 +sprucewoodhalfblock,126,1 +sprucewhalfblock,126,1 +sprucehalfblock,126,1 +darkwoodenstep,126,1 +darkwoodstep,126,1 +darkwstep,126,1 +darkstep,126,1 +darkwoodenslab,126,1 +darkwoodslab,126,1 +darkwslab,126,1 +darkslab,126,1 +darkwoodenhalfblock,126,1 +darkwoodhalfblock,126,1 +darkwhalfblock,126,1 +darkhalfblock,126,1 +birchwoodenstep,126,2 +birchwoodstep,126,2 +birchwstep,126,2 +birchstep,126,2 +birchwoodenslab,126,2 +birchwoodslab,126,2 +birchwslab,126,2 +birchslab,126,2 +birchwoodenhalfblock,126,2 +birchwoodhalfblock,126,2 +birchwhalfblock,126,2 +birchhalfblock,126,2 +lightwoodenstep,126,2 +lightwoodstep,126,2 +lightwstep,126,2 +lightstep,126,2 +lstep,126,2 +lightwoodenslab,126,2 +lightwoodslab,126,2 +lightwslab,126,2 +lightslab,126,2 +lslab,126,2 +lightwoodenhalfblock,126,2 +lightwoodhalfblock,126,2 +lightwhalfblock,126,2 +lighthalfblock,126,2 +lhalfblock,126,2 +junglewoodenstep,126,3 +junglewoodstep,126,3 +junglewstep,126,3 +junglestep,126,3 +jstep,126,3 +junglewoodenslab,126,3 +junglewoodslab,126,3 +junglewslab,126,3 +jungleslab,126,3 +jslab,126,3 +junglewoodenhalfblock,126,3 +junglewoodhalfblock,126,3 +junglewhalfblock,126,3 +junglehalfblock,126,3 +jhalfblock,126,3 +forestwoodenstep,126,3 +forestwoodstep,126,3 +forestwstep,126,3 +foreststep,126,3 +fstep,126,3 +forestwoodenslab,126,3 +forestwoodslab,126,3 +forestwslab,126,3 +forestslab,126,3 +fslab,126,3 +forestwoodenhalfblock,126,3 +forestwoodhalfblock,126,3 +forestwhalfblock,126,3 +foresthalfblock,126,3 +fhalfblock,126,3 +acaciawoodenstep,126,4 +acaciawoodstep,126,4 +acaciawstep,126,4 +acaciastep,126,4 +astep,126,4 +acaciawoodenslab,126,4 +acaciawoodslab,126,4 +acaciawslab,126,4 +acaciaslab,126,4 +aslab,126,4 +acaciawoodenhalfblock,126,4 +acaciawoodhalfblock,126,4 +acaciawhalfblock,126,4 +acaciahalfblock,126,4 +ahalfblock,126,4 +darkoakwoodenstep,126,5 +darkoakwoodstep,126,5 +darkoakwstep,126,5 +darkoakstep,126,5 +dostep,126,5 +darkoakwoodenslab,126,5 +darkoakwoodslab,126,5 +darkoakwslab,126,5 +darkoakslab,126,5 +doslab,126,5 +darkoakwoodenhalfblock,126,5 +darkoakwoodhalfblock,126,5 +darkoakwhalfblock,126,5 +darkoakhalfblock,126,5 +dohalfblock,126,5 +cocoaplant,127,0 +cocoplant,127,0 +cplant,127,0 +cocoafruit,127,0 +cocofruit,127,0 +cfruit,127,0 +cocoapod,127,0 +cocopod,127,0 +cpod,127,0 +sandstonestairs,128,0 +sandstairs,128,0 +sandsstairs,128,0 +sstonestairs,128,0 +ssstairs,128,0 +sandstair,128,0 +sandstonestair,128,0 +sandsstair,128,0 +sstonestair,128,0 +ssstair,128,0 +emeraldore,129,0 +eore,129,0 +oreemerald,129,0 +oree,129,0 +enderchest,130,0 +endchest,130,0 +echest,130,0 +chestender,130,0 +chestend,130,0 +cheste,130,0 +endercontainer,130,0 +endcontainer,130,0 +econtainer,130,0 +tripwirehook,131,0 +tripwire,131,0 +trip,131,0 +tripwirelever,131,0 +triphook,131,0 +emeraldblock,133,0 +blockemerald,133,0 +eblock,133,0 +blocke,133,0 +sprucewoodenstairs,134,0 +sprucewoodstairs,134,0 +sprucewstairs,134,0 +sprucestairs,134,0 +darkwoodenstairs,134,0 +darkwoodstairs,134,0 +darkwstairs,134,0 +darkstairs,134,0 +dstairs,134,0 +sprucewoodenstair,134,0 +sprucewoodstair,134,0 +sprucewstair,134,0 +sprucestair,134,0 +darkwoodenstair,134,0 +darkwoodstair,134,0 +darkwstair,134,0 +darkstair,134,0 +dstair,134,0 +birchwoodenstairs,135,0 +birchwoodstairs,135,0 +birchwstairs,135,0 +birchstairs,135,0 +lightwoodenstairs,135,0 +lightwoodstairs,135,0 +lightwstairs,135,0 +lightstairs,135,0 +lstairs,135,0 +birchwoodenstair,135,0 +birchwoodstair,135,0 +birchwstair,135,0 +birchstair,135,0 +lightwoodenstair,135,0 +lightwoodstair,135,0 +lightwstair,135,0 +lightstair,135,0 +lstair,135,0 +junglewoodenstairs,136,0 +junglewoodstairs,136,0 +junglewstairs,136,0 +junglestairs,136,0 +jstairs,136,0 +forestwoodenstairs,136,0 +forestwoodstairs,136,0 +forestwstairs,136,0 +foreststairs,136,0 +fstairs,136,0 +junglewoodenstair,136,0 +junglewoodstair,136,0 +junglewstair,136,0 +junglestair,136,0 +jstair,136,0 +forestwoodenstair,136,0 +forestwoodstair,136,0 +forestwstair,136,0 +foreststair,136,0 +fstair,136,0 +commandblock,137,0 +blockcommand,137,0 +cmdblock,137,0 +blockcmd,137,0 +macroblock,137,0 +blockmacro,137,0 +beacon,138,0 +beaconblock,138,0 +cobblestonewall,139,0 +cstonewall,139,0 +cobblewall,139,0 +cobblestonefence,139,0 +cstonefence,139,0 +cobblefence,139,0 +cswall,139,0 +csfence,139,0 +cwall,139,0 +cfence,139,0 +mosscobblestonewall,139,1 +mosscstonewall,139,1 +mosscobblewall,139,1 +mcobblestonewall,139,1 +mcstonewall,139,1 +mcobblewall,139,1 +mosscobblestonefence,139,1 +mosscstonefence,139,1 +mosscobblefence,139,1 +mcobblestonefence,139,1 +mcstonefence,139,1 +mcobblefence,139,1 +mcswall,139,0 +mcsfence,139,0 +mcwall,139,0 +mcfence,139,0 +plantedcarrot,141,0 +plantcarrot,141,0 +carrots,141,0 +growingcarrot,141,0 +potatoplant,142,0 +potatoes,142,0 +plantedpotato,142,0 +plantpotato,142,0 +growingpotato,142,0 +woodenbutton,143,0 +woodenplankbutton,143,0 +woodplankbutton,143,0 +wplankbutton,143,0 +plankbutton,143,0 +woodbutton,143,0 +wbutton,143,0 +anvil,145,0 +slightlydamagedanvil,145,1 +slightdamageanvil,145,1 +damagedanvil,145,1 +verydamagedanvil,145,2 +trapchest,146,0 +trappedchest,146,0 +chesttrapped,146,0 +chesttrap,146,0 +goldpressureplate,147,0 +weightedgoldpressureplate,147,0 +weightgoldpressureplate,147,0 +wgoldpressureplate,147,0 +weightedgoldpressplate,147,0 +weightgoldpressplate,147,0 +wgoldpressplate,147,0 +goldpressplate,147,0 +weightedgoldpplate,147,0 +weightgoldpplate,147,0 +wgoldpplate,147,0 +goldpplate,147,0 +weightedgoldplate,147,0 +weightgoldplate,147,0 +wgoldplate,147,0 +goldplate,147,0 +weightedgpressureplate,147,0 +weightgpressureplate,147,0 +wgpressureplate,147,0 +gpressureplate,147,0 +weightedgpressplate,147,0 +weightgpressplate,147,0 +wgpressplate,147,0 +gpressplate,147,0 +weightedgpplate,147,0 +weightgpplate,147,0 +wgpplate,147,0 +gpplate,147,0 +weightedgplate,147,0 +weightgplate,147,0 +wgplate,147,0 +gplate,147,0 +ironpressureplate,148,0 +weightedironpressureplate,148,0 +weightironpressureplate,148,0 +wironpressureplate,148,0 +weightedironpressplate,148,0 +weightironpressplate,148,0 +wironpressplate,148,0 +ironpressplate,148,0 +weightedironpplate,148,0 +weightironpplate,148,0 +wironpplate,148,0 +ironpplate,148,0 +weightedironplate,148,0 +weightironplate,148,0 +wironplate,148,0 +ironplate,148,0 +weightedipressureplate,148,0 +weightipressureplate,148,0 +wipressureplate,148,0 +ipressureplate,148,0 +weightedipressplate,148,0 +weightipressplate,148,0 +wipressplate,148,0 +ipressplate,148,0 +weightedipplate,148,0 +weightipplate,148,0 +wipplate,148,0 +ipplate,148,0 +weightediplate,148,0 +weightiplate,148,0 +wiplate,148,0 +iplate,148,0 +daylightsensor,151,0 +daylightsense,151,0 +lightsensor,151,0 +lightsense,151,0 +daysensor,151,0 +daysense,151,0 +timesensor,151,0 +timesense,151,0 +redstoneblock,152,0 +rstoneblock,152,0 +redsblock,152,0 +rsblock,152,0 +blockredstone,152,0 +blockrstone,152,0 +blockreds,152,0 +blockrs,152,0 +netherquartzore,153,0 +hellquartzore,153,0 +deathquartzore,153,0 +nquartzore,153,0 +hquartzore,153,0 +dquartzore,153,0 +quartzore,153,0 +netherqore,153,0 +hellqore,153,0 +deathqore,153,0 +nqore,153,0 +hqore,153,0 +dqore,153,0 +qore,153,0 +hopper,154,0 +chestpuller,154,0 +chestpull,154,0 +cheststorer,154,0 +cheststore,154,0 +itempuller,154,0 +itempull,154,0 +itemstorer,154,0 +itemstore,154,0 +quartzblock,155,0 +netherquartzblock,155,0 +nqblock,155,0 +qblock,155,0 +chiseledquartzblock,155,1 +chiselquartzblock,155,1 +cquartzblock,155,1 +cqblock,155,1 +pillarquartzblock,155,2 +pquartzblock,155,2 +pqblock,155,2 +quartzstairs,156,0 +qstairs,156,0 +quartzstair,156,0 +qstair,156,0 +activatorrails,157,0 +activaterails,157,0 +triggerrails,157,0 +arails,157,0 +trails,157,0 +activatorrail,157,0 +activaterail,157,0 +triggerrail,157,0 +arail,157,0 +trail,157,0 +activatortrack,157,0 +activatetrack,157,0 +triggertrack,157,0 +atrack,157,0 +ttrack,157,0 +dropper,158,0 +drop,158,0 +chestdispenser,158,0 +chestdispense,158,0 +chestdropper,158,0 +chestdrop,158,0 +whiteclay,159,0 +whitesclay,159,0 +whitestainedclay,159,0 +wclay,159,0 +wsclay,159,0 +wstainedclay,159,0 +sclay,159,0 +stainedclay,159,0 +orangeclay,159,1 +orangesclay,159,1 +orangestainedclay,159,1 +oclay,159,1 +osclay,159,1 +ostainedclay,159,1 +magentaclay,159,2 +magentasclay,159,2 +magentastainedclay,159,2 +mclay,159,2 +msclay,159,2 +mstainedclay,159,2 +lightblueclay,159,3 +lightbluesclay,159,3 +lightbluestainedclay,159,3 +lblueclay,159,3 +lbluesclay,159,3 +lbluestainedclay,159,3 +lightbluclay,159,3 +lightblusclay,159,3 +lightblustainedclay,159,3 +lbluclay,159,3 +lblusclay,159,3 +lblustainedclay,159,3 +lbclay,159,3 +lbsclay,159,3 +lbstainedclay,159,3 +yellowclay,159,4 +yellowsclay,159,4 +yellowstainedclay,159,4 +yclay,159,4 +ysclay,159,4 +ystainedclay,159,4 +lightgreenclay,159,5 +lightgreensclay,159,5 +lightgreenstainedclay,159,5 +lgreenclay,159,5 +lgreensclay,159,5 +lgreenstainedclay,159,5 +lightgreclay,159,5 +lightgresclay,159,5 +lightgrestainedclay,159,5 +lgreclay,159,5 +lgresclay,159,5 +lgrestainedclay,159,5 +limeclay,159,5 +limesclay,159,5 +limestainedclay,159,5 +lclay,159,5 +lsclay,159,5 +lstainedclay,159,5 +pinkclay,159,6 +pinksclay,159,6 +pinkstainedclay,159,6 +piclay,159,6 +pisclay,159,6 +pistainedclay,159,6 +darkgrayclay,159,7 +darkgraysclay,159,7 +darkgraystainedclay,159,7 +dgrayclay,159,7 +dgraysclay,159,7 +dgraystainedclay,159,7 +darkgreyclay,159,7 +darkgreeysclay,159,7 +darkgreystainedclay,159,7 +dgreyclay,159,7 +dgreysclay,159,7 +dgreystainedclay,159,7 +darkgraclay,159,7 +darkgrasclay,159,7 +darkgrastainedclay,159,7 +dgraclay,159,7 +dgrasclay,159,7 +dgrastainedclay,159,7 +grayclay,159,7 +graysclay,159,7 +graystainedclay,159,7 +greyclay,159,7 +greysclay,159,7 +greystainedclay,159,7 +graclay,159,7 +grasclay,159,7 +grastainedclay,159,7 +lightgrayclay,159,8 +lightgraysclay,159,8 +lightgraystainedclay,159,8 +lgrayclay,159,8 +lgraysclay,159,8 +lgraystainedclay,159,8 +lightgreyclay,159,8 +lightgreysclay,159,8 +lightgreystainedclay,159,8 +lgreyclay,159,8 +lgreysclay,159,8 +lgreystainedclay,159,8 +lightgraclay,159,8 +lightgrasclay,159,8 +lightgrastainedclay,159,8 +lgraclay,159,8 +lgrasclay,159,8 +lgrastainedclay,159,8 +silverclay,159,8 +silversclay,159,8 +silverstainedclay,159,8 +siclay,159,8 +siasclay,159,8 +siastainedclay,159,8 +cyanclay,159,9 +cyansclay,159,9 +cyanstainedclay,159,9 +cclay,159,9 +csclay,159,9 +cstainedclay,159,9 +purpleclay,159,10 +purplesclay,159,10 +purplestainedclay,159,10 +puclay,159,10 +pusclay,159,10 +pustainedclay,159,10 +blueclay,159,11 +bluesclay,159,11 +bluestainedclay,159,11 +bluclay,159,11 +blusclay,159,11 +blustainedclay,159,11 +brownclay,159,12 +brownsclay,159,12 +brownstainedclay,159,12 +broclay,159,12 +brosclay,159,12 +brostainedclay,159,12 +darkgreenclay,159,13 +darkgreensclay,159,13 +darkgreenstainedclay,159,13 +dgreenclay,159,13 +dgreensclay,159,13 +dgreenstainedclay,159,13 +greenclay,159,13 +greensclay,159,13 +greenstainedclay,159,13 +darkgreclay,159,13 +darkgresclay,159,13 +darkgrestainedclay,159,13 +dgreclay,159,13 +dgresclay,159,13 +dgrestainedclay,159,13 +greclay,159,13 +gresclay,159,13 +grestainedclay,159,13 +redclay,159,14 +redsclay,159,14 +redstainedclay,159,14 +rclay,159,14 +rsclay,159,14 +rstainedclay,159,14 +blackclay,159,15 +blacksclay,159,15 +blackstainedclay,159,15 +blaclay,159,15 +blasclay,159,15 +blastainedclay,159,15 +whiteglasspane,160,0 +whitesglasspane,160,0 +whitestainedglasspane,160,0 +wglasspane,160,0 +wsglasspane,160,0 +wstainedglasspane,160,0 +sglasspane,160,0 +stainedglasspane,160,0 +orangeglasspane,160,1 +orangesglasspane,160,1 +orangestainedglasspane,160,1 +oglasspane,160,1 +osglasspane,160,1 +ostainedglasspane,160,1 +magentaglasspane,160,2 +magentasglasspane,160,2 +magentastainedglasspane,160,2 +mglasspane,160,2 +msglasspane,160,2 +mstainedglasspane,160,2 +lightblueglasspane,160,3 +lightbluesglasspane,160,3 +lightbluestainedglasspane,160,3 +lblueglasspane,160,3 +lbluesglasspane,160,3 +lbluestainedglasspane,160,3 +lightbluglasspane,160,3 +lightblusglasspane,160,3 +lightblustainedglasspane,160,3 +lbluglasspane,160,3 +lblusglasspane,160,3 +lblustainedglasspane,160,3 +lbglasspane,160,3 +lbsglasspane,160,3 +lbstainedglasspane,160,3 +yellowglasspane,160,4 +yellowsglasspane,160,4 +yellowstainedglasspane,160,4 +yglasspane,160,4 +ysglasspane,160,4 +ystainedglasspane,160,4 +lightgreenglasspane,160,5 +lightgreensglasspane,160,5 +lightgreenstainedglasspane,160,5 +lgreenglasspane,160,5 +lgreensglasspane,160,5 +lgreenstainedglasspane,160,5 +lightgreglasspane,160,5 +lightgresglasspane,160,5 +lightgrestainedglasspane,160,5 +lgreglasspane,160,5 +lgresglasspane,160,5 +lgrestainedglasspane,160,5 +limeglasspane,160,5 +limesglasspane,160,5 +limestainedglasspane,160,5 +lglasspane,160,5 +lsglasspane,160,5 +lstainedglasspane,160,5 +pinkglasspane,160,6 +pinksglasspane,160,6 +pinkstainedglasspane,160,6 +piglasspane,160,6 +pisglasspane,160,6 +pistainedglasspane,160,6 +darkgrayglasspane,160,7 +darkgraysglasspane,160,7 +darkgraystainedglasspane,160,7 +dgrayglasspane,160,7 +dgraysglasspane,160,7 +dgraystainedglasspane,160,7 +darkgreyglasspane,160,7 +darkgreysglasspane,160,7 +darkgreystainedglasspane,160,7 +dgreyglasspane,160,7 +dgreysglasspane,160,7 +dgreystainedglasspane,160,7 +darkgraglasspane,160,7 +darkgrasglasspane,160,7 +darkgrastainedglasspane,160,7 +dgraglasspane,160,7 +dgrasglasspane,160,7 +dgrastainedglasspane,160,7 +grayglasspane,160,7 +graysglasspane,160,7 +graystainedglasspane,160,7 +greyglasspane,160,7 +greysglasspane,160,7 +greystainedglasspane,160,7 +graglasspane,160,7 +grasglasspane,160,7 +grastainedglasspane,160,7 +lightgrayglasspane,160,8 +lightgraysglasspane,160,8 +lightgraystainedglasspane,160,8 +lgrayglasspane,160,8 +lgraysglasspane,160,8 +lgraystainedglasspane,160,8 +lightgreyglasspane,160,8 +lightgreysglasspane,160,8 +lightgreystainedglasspane,160,8 +lgreyglasspane,160,8 +lgreysglasspane,160,8 +lgreystainedglasspane,160,8 +lightgraglasspane,160,8 +lightgrasglasspane,160,8 +lightgrastainedglasspane,160,8 +lgraglasspane,160,8 +lgrasglasspane,160,8 +lgrastainedglasspane,160,8 +silverglasspane,160,8 +silversglasspane,160,8 +silverstainedglasspane,160,8 +siglasspane,160,8 +siasglasspane,160,8 +siastainedglasspane,160,8 +cyanglasspane,160,9 +cyansglasspane,160,9 +cyanstainedglasspane,160,9 +cglasspane,160,9 +csglasspane,160,9 +cstainedglasspane,160,9 +purpleglasspane,160,10 +purplesglasspane,160,10 +purplestainedglasspane,160,10 +puglasspane,160,10 +pusglasspane,160,10 +pustainedglasspane,160,10 +blueglasspane,160,11 +bluesglasspane,160,11 +bluestainedglasspane,160,11 +bluglasspane,160,11 +blusglasspane,160,11 +blustainedglasspane,160,11 +brownglasspane,160,12 +brownsglasspane,160,12 +brownstainedglasspane,160,12 +broglasspane,160,12 +brosglasspane,160,12 +brostainedglasspane,160,12 +darkgreenglasspane,160,13 +darkgreensglasspane,160,13 +darkgreenstainedglasspane,160,13 +dgreenglasspane,160,13 +dgreensglasspane,160,13 +dgreenstainedglasspane,160,13 +greenglasspane,160,13 +greensglasspane,160,13 +greenstainedglasspane,160,13 +darkgreglasspane,160,13 +darkgresglasspane,160,13 +darkgrestainedglasspane,160,13 +dgreglasspane,160,13 +dgresglasspane,160,13 +dgrestainedglasspane,160,13 +greglasspane,160,13 +gresglasspane,160,13 +grestainedglasspane,160,13 +redglasspane,160,14 +redsglasspane,160,14 +redstainedglasspane,160,14 +rglasspane,160,14 +rsglasspane,160,14 +rstainedglasspane,160,14 +blackglasspane,160,15 +blacksglasspane,160,15 +blackstainedglasspane,160,15 +blaglasspane,160,15 +blasglasspane,160,15 +blastainedglasspane,160,15 +acacialeaves,161,0 +acaciatreeleaves,161,0 +acacialogleaves,161,0 +acaciatrunkleaves,161,0 +acaciawoodleaves,161,0 +aleaves,161,0 +atreeleaves,161,0 +alogleaves,161,0 +atrunkleaves,161,0 +awoodleaves,161,0 +acacialeave,161,0 +acaciatreeleave,161,0 +acacialogleave,161,0 +acaciatrunkleave,161,0 +acaciawoodleave,161,0 +aleave,161,0 +atreeleave,161,0 +alogleave,161,0 +atrunkleave,161,0 +awoodleave,161,0 +acaciatreeleaf,161,0 +acacialogleaf,161,0 +acaciatrunkleaf,161,0 +acaciawoodleaf,161,0 +aleaf,161,0 +atreeleaf,161,0 +alogleaf,161,0 +atrunkleaf,161,0 +awoodleaf,161,0 +darkoakleaves,161,1 +darkoaktreeleaves,161,1 +darkoaklogleaves,161,1 +darkoaktrunkleaves,161,1 +darkoakwoodleaves,161,1 +doakleaves,161,1 +doaktreeleaves,161,1 +doaklogleaves,161,1 +doaktrunkleaves,161,1 +doakwoodleaves,161,1 +doleaves,161,1 +dotreeleaves,161,1 +dologleaves,161,1 +dotrunkleaves,161,1 +dowoodleaves,161,1 +darkoakleave,161,1 +darkoaktreeleave,161,1 +darkoaklogleave,161,1 +darkoaktrunkleave,161,1 +darkoakwoodleave,161,1 +doakleave,161,1 +doaktreeleave,161,1 +doaklogleave,161,1 +doaktrunkleave,161,1 +doakwoodleave,161,1 +doleave,161,1 +dotreeleave,161,1 +dologleave,161,1 +dotrunkleave,161,1 +dowoodleave,161,1 +darkoaktreeleaf,161,1 +darkoaklogleaf,161,1 +darkoaktrunkleaf,161,1 +darkoakwoodleaf,161,1 +doakleaf,161,1 +doaktreeleaf,161,1 +doaklogleaf,161,1 +doaktrunkleaf,161,1 +doakwoodleaf,161,1 +doleaf,161,1 +dotreeleaf,161,1 +dologleaf,161,1 +dotrunkleaf,161,1 +dowoodleaf,161,1 +acacia,162,0 +acaciatree,162,0 +acacialog,162,0 +acaciatrunk,162,0 +acaciawood,162,0 +atree,162,0 +alog,162,0 +atrunk,162,0 +awood,162,0 +darkoak,162,1 +darkoaktree,162,1 +darkoaklog,162,1 +darkoaktrunk,162,1 +darkoakwood,162,1 +doak,162,1 +doaktree,162,1 +doaklog,162,1 +doaktrunk,162,1 +doakwood,162,1 +dotree,162,1 +dolog,162,1 +dotrunk,162,1 +dowood,162,1 +acaciawoodenstairs,163,0 +acaciawoodstairs,163,0 +acaciawstairs,163,0 +acaciastairs,163,0 +awoodenstairs,163,0 +awoodstairs,163,0 +awstairs,163,0 +astairs,163,0 +acaciawoodenstair,163,0 +acaciawoodstair,163,0 +acaciawstair,163,0 +acaciastair,163,0 +awoodenstair,163,0 +awoodstair,163,0 +awstair,163,0 +astair,163,0 +darkoakwoodenstairs,164,0 +darkoakwoodstairs,164,0 +darkoakwstairs,164,0 +darkoakstairs,164,0 +doakwoodenstairs,164,0 +doakwoodstairs,164,0 +doakwstairs,164,0 +doakstairs,164,0 +dowoodenstairs,164,0 +dowoodstairs,164,0 +dowstairs,164,0 +dostairs,164,0 +darkoakwoodenstair,164,0 +darkoakwoodstair,164,0 +darkoakwstair,164,0 +darkoakstair,164,0 +doakwoodenstair,164,0 +doakwoodstair,164,0 +doakwstair,164,0 +doakstair,164,0 +dowoodenstair,164,0 +dowoodstair,164,0 +dowstair,164,0 +dostair,164,0 +hay,170,0 +hayblock,170,0 +haybale,170,0 +baleofhay,170,0 +hayofbale,170,0 +whitecarpet,171,0 +whitefloor,171,0 +wcarpet,171,0 +wfloor,171,0 +carpet,171,0 +floor,171,0 +orangecarpet,171,1 +orangefloor,171,1 +ocarpet,171,1 +ofloor,171,1 +magentacarpet,171,2 +magentafloor,171,2 +mcarpet,171,2 +mfloor,171,2 +lightbluecarpet,171,3 +lightbluefloor,171,3 +lbluecarpet,171,3 +lbluefloor,171,3 +lbcarpet,171,3 +lbfloor,171,3 +lightblucarpet,171,3 +lightblufloor,171,3 +lblucarpet,171,3 +lblufloor,171,3 +yellowcarpet,171,4 +yellowfloor,171,4 +ycarpet,171,4 +yfloor,171,4 +lightgreencarpet,171,5 +lightgreenfloor,171,5 +lgreencarpet,171,5 +lgreenfloor,171,5 +lightgrecarpet,171,5 +lightgrefloor,171,5 +lgrecarpet,171,5 +lgrefloor,171,5 +limecarpet,171,5 +limefloor,171,5 +lcarpet,171,5 +lfloor,171,5 +pinkcarpet,171,6 +pinkfloor,171,6 +picarpet,171,6 +pifloor,171,6 +darkgraycarpet,171,7 +darkgrayfloor,171,7 +dgraycarpet,171,7 +dgrayfloor,171,7 +darkgreycarpet,171,7 +darkgreyfloor,171,7 +dgreycarpet,171,7 +dgreyfloor,171,7 +darkgracarpet,171,7 +darkgrafloor,171,7 +dgracarpet,171,7 +dgrafloor,171,7 +graycarpet,171,7 +grayfloor,171,7 +greycarpet,171,7 +greyfloor,171,7 +gracarpet,171,7 +grafloor,171,7 +lightgraycarpet,171,8 +lightgrayfloor,171,8 +lgraycarpet,171,8 +lgrayfloor,171,8 +lightgreycarpet,171,8 +lightgreyfloor,171,8 +lgreycarpet,171,8 +lgreyfloor,171,8 +lightgracarpet,171,8 +lightgrafloor,171,8 +lgracarpet,171,8 +lgrafloor,171,8 +silvercarpet,171,8 +silverfloor,171,8 +sicarpet,171,8 +siafloor,171,8 +cyancarpet,171,9 +cyanfloor,171,9 +ccarpet,171,9 +cfloor,171,9 +purplecarpet,171,10 +purplefloor,171,10 +pucarpet,171,10 +pufloor,171,10 +bluecarpet,171,11 +bluefloor,171,11 +blucarpet,171,11 +blufloor,171,11 +browncarpet,171,12 +brownfloor,171,12 +brocarpet,171,12 +brofloor,171,12 +darkgreencarpet,171,13 +darkgreenfloor,171,13 +dgreencarpet,171,13 +dgreenfloor,171,13 +greencarpet,171,13 +greenfloor,171,13 +darkgrecarpet,171,13 +darkgrefloor,171,13 +dgrecarpet,171,13 +dgrefloor,171,13 +grecarpet,171,13 +grefloor,171,13 +redcarpet,171,14 +redfloor,171,14 +rcarpet,171,14 +rfloor,171,14 +blackcarpet,171,15 +blackfloor,171,15 +blacarpet,171,15 +blafloor,171,15 +hardenedclay,172,0 +hardclay,172,0 +hclay,172,0 +coalblock,173,0 +blockcoal,173,0 +coblock,173,0 +blockco,173,0 +coalb,173,0 +bcoal,173,0 +packedice,174,0 +packice,174,0 +solidice,174,0 +sunflower,175,0 +yellowsunflower,175,0 +lilac,175,1 +magentalilac,175,1 +syringa,175,1 +longtallgrass,175,2 +extratallgrass,175,2 +doubletallgrass,175,2 +largetallgrass,175,2 +longtgrass,175,2 +extratgrass,175,2 +doubletgrass,175,2 +largetgrass,175,2 +ltgrass,175,2 +etgrass,175,2 +dtgrass,175,2 +bigfern,175,3 +largefern,175,3 +doublefern,175,3 +bfern,175,3 +lfern,175,3 +dfern,175,3 +rosebush,175,4 +redrosebush,175,4 +peony,175,5 +pinkpeony,175,5 +paeonia,175,5 +ironshovel,256,0 +ironspade,256,0 +ishovel,256,0 +ispade,256,0 +steelshovel,256,0 +steelspade,256,0 +ironpickaxe,257,0 +ironpick,257,0 +steelpickaxe,257,0 +steelpick,257,0 +ipickaxe,257,0 +ipick,257,0 +ironaxe,258,0 +iaxe,258,0 +steelaxe,258,0 +flintandsteel,259,0 +flintandiron,259,0 +flintandtinder,259,0 +flintnsteel,259,0 +flintniron,259,0 +flintntinder,259,0 +flintsteel,259,0 +flintiron,259,0 +flinttinder,259,0 +lighter,259,0 +apple,260,0 +normalapple,260,0 +redapple,260,0 +bow,261,0 +arrow,262,0 +coal,263,0 +charcoal,263,1 +ccoal,263,1 +diamond,264,0 +crystal,264,0 +ironingot,265,0 +ironbar,265,0 +ironi,265,0 +steelingot,265,0 +steelbar,265,0 +steeli,265,0 +iingot,265,0 +ibar,265,0 +ingotiron,265,0 +bariron,265,0 +iiron,265,0 +ingotsteel,265,0 +barsteel,265,0 +isteel,265,0 +ingoti,265,0 +bari,265,0 +goldingot,266,0 +goldbar,266,0 +goldi,266,0 +gingot,266,0 +gbar,266,0 +ingotgold,266,0 +bargold,266,0 +igold,266,0 +ingotg,266,0 +barg,266,0 +ironsword,267,0 +steelsword,267,0 +isword,267,0 +woodensword,268,0 +woodsword,268,0 +wsword,268,0 +woodenshovel,269,0 +woodenspade,269,0 +woodshovel,269,0 +woodspade,269,0 +wshovel,269,0 +wspade,269,0 +woodenpickaxe,270,0 +woodenpick,270,0 +woodpickaxe,270,0 +woodpick,270,0 +wpickaxe,270,0 +wpick,270,0 +woodenaxe,271,0 +woodaxe,271,0 +waxe,271,0 +stonesword,272,0 +cobblestonesword,272,0 +cstonesword,272,0 +cssword,272,0 +ssword,272,0 +stoneshovel,273,0 +cobblestoneshovel,273,0 +cobblestonespade,273,0 +cstoneshovel,273,0 +cstonespade,273,0 +stonespade,273,0 +csshovel,273,0 +csspade,273,0 +sshovel,273,0 +sspade,273,0 +stonepickaxe,274,0 +cobblestonepickaxe,274,0 +cobblestonepick,274,0 +cstonepickaxe,274,0 +cstonepick,274,0 +stonepick,274,0 +cspickaxe,274,0 +cspick,274,0 +spickaxe,274,0 +spick,274,0 +stoneaxe,275,0 +cobblestoneaxe,275,0 +cstoneaxe,275,0 +csaxe,275,0 +saxe,275,0 +diamondsword,276,0 +crystalsword,276,0 +dsword,276,0 +diamondshovel,277,0 +diamondspade,277,0 +crystalshovel,277,0 +crystalspade,277,0 +dshovel,277,0 +dspade,277,0 +diamondpickaxe,278,0 +diamondpick,278,0 +crystalpickaxe,278,0 +crystalpick,278,0 +dpickaxe,278,0 +dpick,278,0 +diamondaxe,279,0 +crystalaxe,279,0 +daxe,279,0 +stick,280,0 +twig,280,0 +branch,280,0 +bowl,281,0 +woodenbowl,281,0 +woodbowl,281,0 +mushroomsoup,282,0 +mrsoup,282,0 +soup,282,0 +goldsword,283,0 +gsword,283,0 +goldshovel,284,0 +goldspade,284,0 +gshovel,284,0 +gspade,284,0 +goldpickaxe,285,0 +goldpick,285,0 +gpickaxe,285,0 +gpick,285,0 +goldaxe,286,0 +gaxe,286,0 +string,287,0 +thread,287,0 +feather,288,0 +gunpowder,289,0 +sulfur,289,0 +woodenhoe,290,0 +woodhoe,290,0 +whoe,290,0 +stonehoe,291,0 +cobblestonehoe,291,0 +cstonehoe,291,0 +cshoe,291,0 +shoe,291,0 +ironhoe,292,0 +steelhoe,292,0 +ihoe,292,0 +diamondhoe,293,0 +crystalhoe,293,0 +dhoe,293,0 +goldhoe,294,0 +ghoe,294,0 +seeds,295,0 +seed,295,0 +wheat,296,0 +crops,296,0 +crop,296,0 +bread,297,0 +leatherhelmet,298,0 +leatherhelm,298,0 +leatherhat,298,0 +leathercoif,298,0 +lhelmet,298,0 +lhelm,298,0 +lhat,298,0 +lcoif,298,0 +leatherchestplate,299,0 +leatherplatebody,299,0 +leatherplate,299,0 +leathershirt,299,0 +leathertunic,299,0 +lchestplate,299,0 +lplatebody,299,0 +lplate,299,0 +lshirt,299,0 +ltunic,299,0 +leatherleggings,300,0 +leatherlegs,300,0 +leatherpants,300,0 +lleggings,300,0 +llegs,300,0 +lpants,300,0 +leatherboots,301,0 +leathershoes,301,0 +lboots,301,0 +lshoes,301,0 +chainmailhelmet,302,0 +chainmailhelm,302,0 +chainmailhat,302,0 +chainmailcoif,302,0 +chainmhelmet,302,0 +chainmhelm,302,0 +chainmhat,302,0 +chainmcoif,302,0 +cmailhelmet,302,0 +cmailhelm,302,0 +cmailhat,302,0 +cmailcoif,302,0 +chainhelmet,302,0 +chainhelm,302,0 +chainhat,302,0 +chaincoif,302,0 +cmhelmet,302,0 +cmhelm,302,0 +cmhat,302,0 +cmcoif,302,0 +chainmailchestplate,303,0 +chainmailplatebody,303,0 +chainmailplate,303,0 +chainmailshirt,303,0 +chainmailtunic,303,0 +chainmchestplate,303,0 +chainmplatebody,303,0 +chainmplate,303,0 +chainmshirt,303,0 +chainmtunic,303,0 +cmailchestplate,303,0 +cmailplatebody,303,0 +cmailplate,303,0 +cmailshirt,303,0 +cmailtunic,303,0 +chainchestplate,303,0 +chainplatebody,303,0 +chainplate,303,0 +chainshirt,303,0 +chaintunic,303,0 +cmchestplate,303,0 +cmplatebody,303,0 +cmplate,303,0 +cmshirt,303,0 +cmtunic,303,0 +chainmailleggings,304,0 +chainmaillegs,304,0 +chainmailpants,304,0 +chainmleggings,304,0 +chainmlegs,304,0 +chainmpants,304,0 +cmailleggings,304,0 +cmaillegs,304,0 +cmailpants,304,0 +chainleggings,304,0 +chainlegs,304,0 +chainpants,304,0 +cmleggings,304,0 +cmlegs,304,0 +cmpants,304,0 +chainmailboots,305,0 +chainmailshoes,305,0 +chainmboots,305,0 +chainmshoes,305,0 +cmailboots,305,0 +cmailshoes,305,0 +chainboots,305,0 +chainshoes,305,0 +cmboots,305,0 +cmshoes,305,0 +ironhelmet,306,0 +ironhelm,306,0 +ironhat,306,0 +ironcoif,306,0 +ihelmet,306,0 +ihelm,306,0 +ihat,306,0 +icoif,306,0 +steelhelmet,306,0 +steelhelm,306,0 +steelhat,306,0 +steelcoif,306,0 +shelmet,306,0 +shelm,306,0 +shat,306,0 +scoif,306,0 +ironchestplate,307,0 +ironplatebody,307,0 +ironshirt,307,0 +irontunic,307,0 +ichestplate,307,0 +iplatebody,307,0 +ishirt,307,0 +itunic,307,0 +steelchestplate,307,0 +steelplatebody,307,0 +steelplate,307,0 +steelshirt,307,0 +steeltunic,307,0 +schestplate,307,0 +splatebody,307,0 +sshirt,307,0 +stunic,307,0 +ironleggings,308,0 +ironlegs,308,0 +ironpants,308,0 +ileggings,308,0 +ilegs,308,0 +ipants,308,0 +steelleggings,308,0 +steellegs,308,0 +steelpants,308,0 +sleggings,308,0 +slegs,308,0 +spants,308,0 +ironboots,309,0 +ironshoes,309,0 +iboots,309,0 +ishoes,309,0 +steelboots,309,0 +steelshoes,309,0 +sboots,309,0 +sshoes,309,0 +diamondhelmet,310,0 +diamondhelm,310,0 +diamondhat,310,0 +diamondcoif,310,0 +dhelmet,310,0 +dhelm,310,0 +dhat,310,0 +dcoif,310,0 +crystalhelmet,310,0 +crystalhelm,310,0 +crystalhat,310,0 +crystalcoif,310,0 +chelmet,310,0 +chelm,310,0 +chat,310,0 +ccoif,310,0 +diamondchestplate,311,0 +diamondplatebody,311,0 +diamondplate,311,0 +diamondshirt,311,0 +diamondtunic,311,0 +dchestplate,311,0 +dplatebody,311,0 +dplate,311,0 +dshirt,311,0 +dtunic,311,0 +crystalchestplate,311,0 +crystalplatebody,311,0 +crystalplate,311,0 +crystalshirt,311,0 +crystaltunic,311,0 +cchestplate,311,0 +cplatebody,311,0 +cplate,311,0 +cshirt,311,0 +ctunic,311,0 +diamondleggings,312,0 +diamondlegs,312,0 +diamondpants,312,0 +dleggings,312,0 +dlegs,312,0 +dpants,312,0 +crystalleggings,312,0 +crystallegs,312,0 +crystalpants,312,0 +cleggings,312,0 +clegs,312,0 +cpants,312,0 +diamondboots,313,0 +diamondshoes,313,0 +dboots,313,0 +dshoes,313,0 +crystalboots,313,0 +crystalshoes,313,0 +cboots,313,0 +cshoes,313,0 +goldhelmet,314,0 +goldhelm,314,0 +goldhat,314,0 +goldcoif,314,0 +ghelmet,314,0 +ghelm,314,0 +ghat,314,0 +gcoif,314,0 +goldchestplate,315,0 +goldplatebody,315,0 +goldshirt,315,0 +goldtunic,315,0 +gchestplate,315,0 +gplatebody,315,0 +gplateplate,315,0 +gshirt,315,0 +gtunic,315,0 +goldleggings,316,0 +goldlegs,316,0 +goldpants,316,0 +gleggings,316,0 +glegs,316,0 +gpants,316,0 +goldboots,317,0 +goldshoes,317,0 +gboots,317,0 +gshoes,317,0 +flint,318,0 +pork,319,0 +porkchop,319,0 +rawpork,319,0 +rpork,319,0 +rawporkchop,319,0 +rporkchop,319,0 +cookedpork,320,0 +grilledpork,320,0 +grillpork,320,0 +gpork,320,0 +cookpork,320,0 +cpork,320,0 +grilledporkchop,320,0 +grillporkchop,320,0 +gporkchop,320,0 +cookedporkchop,320,0 +cookporkchop,320,0 +cporkchop,320,0 +bacon,320,0 +painting,321,0 +picture,321,0 +goldenapple,322,0 +goldapple,322,0 +gapple,322,0 +enchantedgoldenapple,322,1 +enchantedgoldapple,322,1 +enchantedgapple,322,1 +supergoldenapple,322,1 +supergoldapple,322,1 +supergapple,322,1 +magicalgoldenapple,322,1 +magicalgoldapple,322,1 +magicalgapple,322,1 +magicgoldenapple,322,1 +magicgoldapple,322,1 +magicgapple,322,1 +egoldenapple,322,1 +egoldapple,322,1 +egapple,322,1 +sgoldenapple,322,1 +sgoldapple,322,1 +sgapple,322,1 +mgoldenapple,322,1 +mgoldapple,322,1 +mgapple,322,1 +sign,323,0 +woodendoor,324,0 +wooddoor,324,0 +wdoor,324,0 +door,324,0 +bucket,325,0 +bukkit,325,0 +waterbucket,326,0 +waterbukkit,326,0 +wbucket,326,0 +wbukkit,326,0 +magmabucket,327,0 +magmabukkit,327,0 +lavabucket,327,0 +lavabukkit,327,0 +lbucket,327,0 +lbukkit,327,0 +minecart,328,0 +mcart,328,0 +cart,328,0 +saddle,329,0 +irondoor,330,0 +idoor,330,0 +steeldoor,330,0 +sdoor,330,0 +dooriron,330,0 +doori,330,0 +doorsteel,330,0 +doors,330,0 +redstonedust,331,0 +redstone,331,0 +rstonedust,331,0 +rstone,331,0 +redsdust,331,0 +reddust,331,0 +rsdust,331,0 +rdust,331,0 +snow,332,0 +snowball,332,0 +snball,332,0 +sball,332,0 +boat,333,0 +leather,334,0 +cowhide,334,0 +hide,334,0 +milkbucket,335,0 +milkbukkit,335,0 +mbucket,335,0 +mbukkit,335,0 +claybrick,336,0 +brick,336,0 +redbrick,336,0 +rbrick,336,0 +clayball,337,0 +cball,337,0 +clay,337,0 +reeds,338,0 +reed,338,0 +sugarcane,338,0 +scane,338,0 +bamboo,338,0 +paper,339,0 +papyrus,339,0 +book,340,0 +slimeball,341,0 +slball,341,0 +chestminecart,342,0 +storageminecart,342,0 +storagemcart,342,0 +chestmcart,342,0 +storagecart,342,0 +chestcart,342,0 +sminecart,342,0 +cminecart,342,0 +smcart,342,0 +cmcart,342,0 +scart,342,0 +ccart,342,0 +furnaceminecart,343,0 +engineminecart,343,0 +poweredminecart,343,0 +powerminecart,343,0 +enginemcart,343,0 +poweredmcart,343,0 +powermcart,343,0 +furnacemcart,343,0 +enginecart,343,0 +poweredcart,343,0 +powercart,343,0 +furnacecart,343,0 +eminecart,343,0 +pminecart,343,0 +fminecart,343,0 +emcart,343,0 +pmcart,343,0 +fmcart,343,0 +ecart,343,0 +pcart,343,0 +fcart,343,0 +egg,344,0 +compass,345,0 +fishingrod,346,0 +fishrod,346,0 +frod,346,0 +rod,346,0 +watch,347,0 +goldwatch,347,0 +goldclock,347,0 +gwatch,347,0 +gclock,347,0 +clock,347,0 +glowstonedust,348,0 +glowingstonedust,348,0 +lightstonedust,348,0 +lbdust,348,0 +gbdust,348,0 +lsdust,348,0 +gsdust,348,0 +rawfish,349,0 +rafish,349,0 +fish,349,0 +rawsalmonfish,349,1 +rasalmonfish,349,1 +salmonfish,349,1 +rawsalmon,349,1 +rasalmon,349,1 +salmon,349,1 +sfish,349,1 +fishs,349,1 +rawclownfish,349,2 +raclownfish,349,2 +clownfish,349,2 +rawnemo,349,2 +ranemo,349,2 +nemo,349,2 +nemofish,349,2 +fishnemo,349,2 +clfish,349,2 +fishcl,349,2 +nfish,349,2 +fishn,349,2 +rawpufferfish,349,3 +rapufferfish,349,3 +pufferfish,349,3 +pufffish,349,3 +fishpuff,349,3 +pfish,349,3 +fishp,349,3 +cookedfish,350,0 +cookfish,350,0 +cfish,350,0 +grilledfish,350,0 +grillfish,350,0 +gfish,350,0 +roastedfish,350,0 +roastfish,350,0 +rofish,350,0 +cookedsalmonfish,350,1 +cooksalmonfish,350,1 +csalmonfish,350,1 +grilledsalmonfish,350,1 +grillsalmonfish,350,1 +gsalmonfish,350,1 +roastedsalmonfish,350,1 +roastsalmonfish,350,1 +rosalmonfish,350,1 +cookedsalmon,350,1 +cooksalmon,350,1 +csalmon,350,1 +grilledsalmon,350,1 +grillsalmon,350,1 +gsalmon,350,1 +roastedsalmon,350,1 +roastsalmon,350,1 +rosalmon,350,1 +dye,351,0 +inksack,351,0 +inksac,351,0 +isack,351,0 +isac,351,0 +sack,351,0 +sac,351,0 +blackinksack,351,0 +blackinksac,351,0 +blackisack,351,0 +blackisac,351,0 +blacksack,351,0 +blacksac,351,0 +inksackblack,351,0 +inksacblack,351,0 +isackblack,351,0 +isacblack,351,0 +sackblack,351,0 +sacblack,351,0 +blackinksackcolour,351,0 +blackinksaccolour,351,0 +blackisackcolour,351,0 +blackisaccolour,351,0 +blacksackcolour,351,0 +blacksaccolour,351,0 +inksackblackcolour,351,0 +inksacblackcolour,351,0 +isackblackcolour,351,0 +isacclackcolour,351,0 +sackblackcolour,351,0 +sacblackcolour,351,0 +blackinksackcolor,351,0 +blackinksaccolor,351,0 +blackisackcolor,351,0 +blackisaccolor,351,0 +blacksackcolor,351,0 +blacksaccolor,351,0 +inksackblackcolor,351,0 +inksacblackcolor,351,0 +isackblackcolor,351,0 +isacblackcolor,351,0 +sackblackcolor,351,0 +sacblackcolor,351,0 +blackinksackdye,351,0 +blackinksacdye,351,0 +blackisackdye,351,0 +blackisacdye,351,0 +blacksackdye,351,0 +blacksacdye,351,0 +inksackblackdye,351,0 +inksacblackdye,351,0 +isackblackdye,351,0 +isacclackdye,351,0 +sackblackdye,351,0 +sacblackdye,351,0 +blackcolor,351,0 +blackdye,351,0 +rosered,351,1 +roseredcolor,351,1 +roseredcolour,351,1 +rosereddye,351,1 +redrosecolor,351,1 +redrosecolour,351,1 +redrosedye,351,1 +redr,351,1 +redrcolor,351,1 +redrcolour,351,1 +redrdye,351,1 +redcolor,351,1 +redcolour,351,1 +reddye,351,1 +cactusgreen,351,2 +greencactus,351,2 +cactusgreencolour,351,2 +greencactuscolour,351,2 +cactusgreencolor,351,2 +greencactuscolor,351,2 +cactusgreendye,351,2 +greencactusdye,351,2 +greencolour,351,2 +greencolor,351,2 +greendye,351,2 +cocoabeans,351,3 +cocoabean,351,3 +cocobeans,351,3 +cocobean,351,3 +cbeans,351,3 +cbean,351,3 +beans,351,3 +bean,351,3 +browncocoabeans,351,3 +browncocoabean,351,3 +browncocobeans,351,3 +browncocobean,351,3 +browncbeans,351,3 +browncbean,351,3 +brownbeans,351,3 +brownbean,351,3 +brownb,351,3 +cocoabeanscolour,351,3 +cocoabeancolour,351,3 +cocobeanscolour,351,3 +cocobeancolour,351,3 +cbeanscolour,351,3 +cbeancolour,351,3 +beanscolour,351,3 +beancolour,351,3 +browncocoabeanscolour,351,3 +browncocoabeancolour,351,3 +browncocobeanscolour,351,3 +browncocobeancolour,351,3 +browncbeanscolour,351,3 +browncbeancolour,351,3 +brownbeanscolour,351,3 +brownbeancolour,351,3 +brownbcolour,351,3 +cocoabeanscolor,351,3 +cocoabeancolor,351,3 +cocobeanscolor,351,3 +cocobeancolor,351,3 +cbeanscolor,351,3 +cbeancolor,351,3 +beanscolor,351,3 +beancolor,351,3 +browncocoabeanscolor,351,3 +browncocoabeancolor,351,3 +browncocobeanscolor,351,3 +browncocobeancolor,351,3 +browncbeanscolor,351,3 +browncbeancolor,351,3 +brownbeanscolor,351,3 +brownbeancolor,351,3 +brownbcolor,351,3 +cocoabeansdye,351,3 +cocoabeandye,351,3 +cocobeansdye,351,3 +cocobeandye,351,3 +cbeansdye,351,3 +cbeandye,351,3 +beansdye,351,3 +beandye,351,3 +browncocoabeansdye,351,3 +browncocoabeandye,351,3 +browncocobeansdye,351,3 +browncocobeandye,351,3 +browncbeansdye,351,3 +browncbeandye,351,3 +brownbeansdye,351,3 +brownbeandye,351,3 +brownbdye,351,3 +browncolour,351,3 +browncolor,351,3 +browndye,351,3 +lapislazuli,351,4 +bluelapislazuli,351,4 +bluelapisl,351,4 +bluelapis,351,4 +bluel,351,4 +lapislazuliblue,351,4 +lapislblue,351,4 +lapisblue,351,4 +lapisl,351,4 +lapis,351,4 +bluelapislazulicolour,351,4 +bluelapislcolour,351,4 +bluelapiscolour,351,4 +lapislazulibluecolour,351,4 +lapislbluecolour,351,4 +lapisbluecolour,351,4 +lapislazulicolour,351,4 +lapislcolour,351,4 +lapiscolour,351,4 +bluelapislazulicolor,351,4 +bluelapislcolor,351,4 +bluelapiscolor,351,4 +lapislazulibluecolor,351,4 +lapislbluecolor,351,4 +lapisbluecolor,351,4 +lapislazulicolor,351,4 +lapislcolor,351,4 +lapiscolor,351,4 +bluelapislazulidye,351,4 +bluelapisldye,351,4 +bluelapisdye,351,4 +lapislazulibluedye,351,4 +lapislbluedye,351,4 +lapisbluedye,351,4 +lapislazulidye,351,4 +lapisldye,351,4 +lapisdye,351,4 +bluecolour,351,4 +bluecolor,351,4 +bluedye,351,4 +purpledye,351,5 +purplecolour,351,5 +purplecolor,351,5 +cyandye,351,6 +cyancolour,351,6 +cyancolor,351,6 +lightgraydye,351,7 +lightgraycolour,351,7 +lightgraycolor,351,7 +lgraycolour,351,7 +lgraycolor,351,7 +lgraydye,351,7 +lightgreydye,351,7 +lightgreycolour,351,7 +lightgreycolor,351,7 +lgreycolour,351,7 +lgreycolor,351,7 +lgreydye,351,7 +silvercolour,351,7 +silvercolor,351,7 +silverdye,351,7 +darkgraydye,351,8 +darkgraycolour,351,8 +darkgraycolor,351,8 +dgraycolour,351,8 +dgraycolor,351,8 +dgraydye,351,8 +graycolour,351,8 +graycolor,351,8 +graydye,351,8 +darkgreydye,351,8 +darkgreycolour,351,8 +darkgreycolor,351,8 +dgreycolour,351,8 +dgreycolor,351,8 +dgreydye,351,8 +greycolour,351,8 +greycolor,351,8 +greydye,351,8 +pinkdye,351,9 +pinkcolour,351,9 +pinkcolor,351,9 +limedye,351,10 +limecolour,351,10 +limecolor,351,10 +dandelionyellow,351,11 +dandelionyellowcolour,351,11 +dandelionyellowcolor,351,11 +dandelionyellowdye,351,11 +yellowdandelioncolour,351,11 +yellowdandelioncolor,351,11 +yellowdandeliondye,351,11 +yellowd,351,11 +yellowdcolour,351,11 +yellowdcolor,351,11 +yellowddye,351,11 +dyellow,351,11 +dyellowcolour,351,11 +dyellowcolor,351,11 +dyellowdye,351,11 +yellowcolour,351,11 +yellowcolor,351,11 +yellowdye,351,11 +lightbluecolour,351,12 +lightbluecolor,351,12 +lightbluedye,351,12 +lbluecolour,351,12 +lbluecolor,351,12 +lbluedye,351,12 +magentacolour,351,13 +magentacolor,351,13 +magentadye,351,13 +orangecolour,351,14 +orangecolor,351,14 +orangedye,351,14 +bonemeal,351,15 +whitebonemeal,351,15 +whitebonemealcolour,351,15 +whitebonemealcolor,351,15 +whitebonemealdye,351,15 +bonemealwhite,351,15 +bonemealwhitecolour,351,15 +bonemealwhitecolor,351,15 +bonemealwhitedye,351,15 +whitebonem,351,15 +whitebonemcolour,351,15 +whitebonemcolor,351,15 +whitebonemdye,351,15 +bonemwhite,351,15 +bonemwhitecolour,351,15 +bonemwhitecolor,351,15 +bonemwhitedye,351,15 +bonemealcolour,351,15 +bonemealcolor,351,15 +bonemealdye,351,15 +bonem,351,15 +bonemcolour,351,15 +bonemcolor,351,15 +bonemdye,351,15 +whitecolour,351,15 +whitecolor,351,15 +whitedye,351,15 +bone,352,0 +sugar,353,0 +whitedust,353,0 +cake,354,0 +bed,355,0 +redstonerepeater,356,0 +redstonerepeat,356,0 +redstonedelayer,356,0 +redstonedelay,356,0 +redstonedioder,356,0 +redstonediode,356,0 +rstonerepeater,356,0 +rstonerepeat,356,0 +rstonedelayer,356,0 +rstonedelay,356,0 +rstonedioder,356,0 +rstonediode,356,0 +redsrepeater,356,0 +redsrepeat,356,0 +redsdelayer,356,0 +redsdelay,356,0 +redsdioder,356,0 +redsdiode,356,0 +rsrepeater,356,0 +rsrepeat,356,0 +rsdelayer,356,0 +rsdelay,356,0 +rsdioder,356,0 +rsdiode,356,0 +repeater,356,0 +repeat,356,0 +delayer,356,0 +delay,356,0 +dioder,356,0 +diode,356,0 +cookie,357,0 +chart,358,0 +map0,358,0 +map1,358,1 +map2,358,2 +map3,358,3 +map4,358,4 +map5,358,5 +map6,358,6 +map7,358,7 +map8,358,8 +map9,358,9 +map10,358,10 +map11,358,11 +map12,358,12 +map13,358,13 +map14,358,14 +map15,358,15 +shears,359,0 +shear,359,0 +sheers,359,0 +sheer,359,0 +woolcutters,359,0 +woolcutter,359,0 +cutterswool,359,0 +cutterwool,359,0 +melonslice,360,0 +mslice,360,0 +slicemelon,360,0 +watermelonslice,360,0 +greenmelonslice,360,0 +melongreenslice,360,0 +pumpkinseeds,361,0 +pseeds,361,0 +seedsp,361,0 +seedspumpkin,361,0 +pumpseeds,361,0 +seedspump,361,0 +melonseeds,362,0 +mseeds,362,0 +watermelonseeds,362,0 +greenmelonseeds,362,0 +gmelonseeds,362,0 +seedsmelon,362,0 +seedswatermelon,362,0 +rawbeef,363,0 +rawsteak,363,0 +uncookedbeef,363,0 +uncookedsteak,363,0 +cowmeat,363,0 +plainbeef,363,0 +beef,364,0 +steak,364,0 +cookedbeef,364,0 +grilledbeef,364,0 +cookedsteak,364,0 +grilledsteak,364,0 +cookedcowmeat,364,0 +rawchicken,365,0 +uncookedchicken,365,0 +plainchicken,365,0 +chickenplain,365,0 +chickenuncooked,365,0 +chickenraw,365,0 +cookedchicken,366,0 +grilledchicken,366,0 +toastedchicken,366,0 +gchicken,366,0 +bbqchicken,366,0 +friedchicken,366,0 +cchicken,366,0 +rottenflesh,367,0 +zombieflesh,367,0 +rottenmeat,367,0 +zombiemeat,367,0 +badflesh,367,0 +poisonflesh,367,0 +zombieremains,367,0 +enderpearl,368,0 +endpearl,368,0 +pearl,368,0 +epearl,368,0 +bluepearl,368,0 +endergem,368,0 +blazerod,369,0 +goldenrod,369,0 +goldrod,369,0 +blazestick,369,0 +goldstick,369,0 +brod,369,0 +grod,369,0 +bstick,369,0 +gstick,369,0 +ghasttear,370,0 +ghastdrop,370,0 +ghosttear,370,0 +ghostdrop,370,0 +gtear,370,0 +gdrop,370,0 +tear,370,0 +goldnugget,371,0 +gnugget,371,0 +goldpebble,371,0 +gpebble,371,0 +goldball,371,0 +gball,371,0 +netherstalk,372,0 +deathstalk,372,0 +hellstalk,372,0 +nstalk,372,0 +dstalk,372,0 +hstalk,372,0 +netherwarts,372,0 +netherwart,372,0 +netherplant,372,0 +nethercrop,372,0 +hellwarts,372,0 +hellwart,372,0 +hellplant,372,0 +hellcrop,372,0 +deathwarts,372,0 +deathwart,372,0 +deathplant,372,0 +deathcrop,372,0 +nwarts,372,0 +nwart,372,0 +ncrop,372,0 +nplant,372,0 +hwarts,372,0 +hwart,372,0 +hplant,372,0 +hcrop,372,0 +dwarts,372,0 +dwart,372,0 +dplant,372,0 +dcrop,372,0 +potion,373,0 +mixture,373,0 +potions,373,0 +waterbottle,373,0 +fullbottle,373,0 +watervase,373,0 +fullvase,373,0 +clearpotion,373,6 +clearpot,373,6 +clearextendedpotion,373,7 +clearexpotion,373,7 +clear2potion,373,7 +clearextendedpot,373,7 +clearexpot,373,7 +clear2pot,373,7 +diffusepotion,373,11 +diffusepot,373,11 +artlesspotion,373,13 +artlesspot,373,13 +thinpotion,373,14 +thinpot,373,14 +thinextendedpotion,373,15 +thinexpotion,373,15 +thin2potion,373,15 +thinextendedpot,373,15 +thinexpot,373,15 +thin2pot,373,15 +awkwardpotion,373,16 +awkwardpot,373,16 +bunglingpotion,373,22 +bunglingpot,373,22 +bunglingextendedpotion,373,23 +bunglingexpotion,373,23 +bungling2potion,373,23 +bunglingextendedpot,373,23 +bunglingexpot,373,23 +bungling2pot,373,23 +smoothpotion,373,27 +smoothpot,373,27 +suavepotion,373,29 +suavepot,373,29 +debonairpotion,373,30 +debonairpot,373,30 +debonairextendedpotion,373,31 +debonairexpotion,373,31 +debonair2potion,373,31 +debonairextendedpot,373,31 +debonairexpot,373,31 +debonair2pot,373,31 +thickpotion,373,32 +thickpot,373,32 +charmingpotion,373,38 +charmingpot,373,38 +charmingextendedpotion,373,39 +charmingexpotion,373,39 +charming2potion,373,39 +charmingextendedpot,373,39 +charmingexpot,373,39 +charming2pot,373,39 +refinedpotion,373,43 +refinedpot,373,43 +cordialpotion,373,45 +cordialpot,373,45 +sparklingpotion,373,46 +sparklingpot,373,46 +sparklingextendedpotion,373,47 +sparklingexpotion,373,47 +sparkling2potion,373,47 +sparklingextendedpot,373,47 +sparklingexpot,373,47 +sparkling2pot,373,47 +potentpotion,373,48 +potentpot,373,48 +rankpotion,373,54 +rankpot,373,54 +rankextendedpotion,373,55 +rankexpotion,373,55 +rank2potion,373,55 +rankextendedpot,373,55 +rankexpot,373,55 +rank2pot,373,55 +acridpotion,373,59 +acridpot,373,59 +grosspotion,373,61 +grosspot,373,61 +stinkypotion,373,62 +stinkypot,373,62 +stinkyextendedpotion,373,63 +stinkyexpotion,373,63 +stinky2potion,373,63 +stinkyextendedpot,373,63 +stinkyexpot,373,63 +stinky2pot,373,63 +mundaneextendedpotion,373,64 +mundaneexpotion,373,64 +mundane2potion,373,64 +mundaneextendedpot,373,64 +mundaneexpot,373,64 +mundane2pot,373,64 +mundanepotion,373,8192 +mundanepot,373,8192 +regenerationpotion,373,8193 +regeneratepotion,373,8193 +regenpotion,373,8193 +regenerationpot,373,8193 +regeneratepot,373,8193 +regenpot,373,8193 +rpot,373,8193 +swiftnesspotion,373,8194 +swiftpotion,373,8194 +speedpotion,373,8194 +swiftnesspot,373,8194 +swiftpot,373,8194 +speedpot,373,8194 +swpot,373,8194 +fireresistancepotion,373,8195 +fireresistpotion,373,8195 +firerespotion,373,8195 +fireresistancepot,373,8195 +fireresistpot,373,8195 +firerespot,373,8195 +fpot,373,8195 +poisonpotion,373,8196 +acidpotion,373,8196 +poisonpot,373,8196 +acidpot,373,8196 +ppot,373,8196 +healingpotion,373,8197 +healpotion,373,8197 +lifepotion,373,8197 +healingpot,373,8197 +healpot,373,8197 +lifepot,373,8197 +hpot,373,8197 +nightvisionpotion,373,8198 +nvisionpotion,373,8198 +nightvpotion,373,8198 +darkvisionpotion,373,8198 +dvisionpotion,373,8198 +darkvpotion,373,8198 +nightvisionpot,373,8198 +nvisionpot,373,8198 +nightvpot,373,8198 +darkvisionpot,373,8198 +dvisionpot,373,8198 +darkvpot,373,8198 +npot,373,8198 +weaknesspotion,373,8200 +weakpotion,373,8200 +weaknesspot,373,8200 +weakpot,373,8200 +wpot,373,8200 +strengthpotion,373,8201 +strongpotion,373,8201 +strpotion,373,8201 +strengthpot,373,8201 +strongpot,373,8201 +strpot,373,8201 +stpot,373,8201 +slownesspotion,373,8202 +slowpotion,373,8202 +slownesspot,373,8202 +slowpot,373,8202 +slpot,373,8202 +harmingpotion,373,8204 +damagepotion,373,8204 +dmgpotion,373,8204 +harmingpot,373,8204 +damagepot,373,8204 +dmgpot,373,8204 +dpot,373,8204 +waterbreathingpotion,373,8205 +waterbreathpotion,373,8205 +breathingpotion,373,8205 +breathpotion,373,8205 +waterbreathingpot,373,8205 +waterbreathpot,373,8205 +breathingpot,373,8205 +breathpot,373,8205 +wbpot,373,8205 +invisibilitypotion,373,8206 +invisiblepotion,373,8206 +invpotion,373,8206 +invisibilitypot,373,8206 +invisiblepot,373,8206 +invpot,373,8206 +ipot,373,8206 +regenerationleveliipotion,373,8225 +regenerateleveliipotion,373,8225 +regenleveliipotion,373,8225 +regenerationlevel2potion,373,8225 +regeneratelevel2potion,373,8225 +regenlevel2potion,373,8225 +regenerationiipotion,373,8225 +regenerateiipotion,373,8225 +regeniipotion,373,8225 +regenerationleveliipot,373,8225 +regenerateleveliipot,373,8225 +regenleveliipot,373,8225 +regenerationlevel2pot,373,8225 +regeneratelevel2pot,373,8225 +regenlevel2pot,373,8225 +regenerationiipot,373,8225 +regenerateiipot,373,8225 +regeniipot,373,8225 +r2pot,373,8225 +swiftnessleveliipotion,373,8226 +swiftleveliipotion,373,8226 +speedleveliipotion,373,8226 +swiftnesslevel2potion,373,8226 +swiftlevel2potion,373,8226 +speedlevel2potion,373,8226 +swiftnessiipotion,373,8226 +swiftiipotion,373,8226 +speediipotion,373,8226 +swiftnessleveliipot,373,8226 +swiftleveliipot,373,8226 +speedleveliipot,373,8226 +swiftnesslevel2pot,373,8226 +swiftlevel2pot,373,8226 +speedlevel2pot,373,8226 +swiftnessiipot,373,8226 +swiftiipot,373,8226 +speediipot,373,8226 +sw2pot,373,8226 +poisonleveliipotion,373,8228 +acidleveliipotion,373,8228 +poisonlevel2potion,373,8228 +acidlevel2potion,373,8228 +poisoniipotion,373,8228 +acidiipotion,373,8228 +poisonleveliipot,373,8228 +acidleveliipot,373,8228 +poisonlevel2pot,373,8228 +acidlevel2pot,373,8228 +poisoniipot,373,8228 +acidiipot,373,8228 +p2pot,373,8228 +healingleveliipotion,373,8229 +healleveliipotion,373,8229 +healinglevel2potion,373,8229 +heallevel2potion,373,8229 +healingiipotion,373,8229 +healiipotion,373,8229 +healingleveliipot,373,8229 +healleveliipot,373,8229 +healinglevel2pot,373,8229 +heallevel2pot,373,8229 +healingiipot,373,8229 +healiipot,373,8229 +h2pot,373,8229 +strengthleveliipotion,373,8233 +strongleveliipotion,373,8233 +strleveliipotion,373,8233 +strengthlevel2potion,373,8233 +stronglevel2potion,373,8233 +strlevel2potion,373,8233 +strengthiipotion,373,8233 +strongiipotion,373,8233 +striipotion,373,8233 +strengthleveliipot,373,8233 +strongleveliipot,373,8233 +strleveliipot,373,8233 +strengthlevel2pot,373,8233 +stronglevel2pot,373,8233 +strlevel2pot,373,8233 +strengthiipot,373,8233 +strongiipot,373,8233 +striipot,373,8233 +st2pot,373,8233 +harmingleveliipotion,373,8236 +damageleveliipotion,373,8236 +dmgleveliipotion,373,8236 +harminglevel2potion,373,8236 +damagelevel2potion,373,8236 +dmglevel2potion,373,8236 +harmingiipotion,373,8236 +damageiipotion,373,8236 +dmgiipotion,373,8236 +harmingleveliipot,373,8236 +damageleveliipot,373,8236 +dmgleveliipot,373,8236 +harminglevel2pot,373,8236 +damagelevel2pot,373,8236 +dmglevel2pot,373,8236 +harmingiipot,373,8236 +damageiipot,373,8236 +dmgiipot,373,8236 +d2pot,373,8236 +regenerationextendedpotion,373,8257 +regenerateextendedpotion,373,8257 +regenextendepotion,373,8257 +regenerationexpotion,373,8257 +regenerateexpotion,373,8257 +regenexpotion,373,8257 +regenerationextendedpot,373,8257 +regenerateextendedpot,373,8257 +regenextendepot,373,8257 +regenerationexpot,373,8257 +regenerateexpot,373,8257 +regenexpot,373,8257 +repot,373,8257 +swiftnessextendedpotion,373,8258 +swiftextendedpotion,373,8258 +speedextendedpotion,373,8258 +swiftnessexpotion,373,8258 +swiftexpotion,373,8258 +speedexpotion,373,8258 +swiftnessextendedpot,373,8258 +swiftextendedpot,373,8258 +speedextendedpot,373,8258 +swiftnessexpot,373,8258 +swiftexpot,373,8258 +speedexpot,373,8258 +swepot,373,8258 +fireresistanceextendedpotion,373,8259 +fireresistextendedpotion,373,8259 +fireresextendedpotion,373,8259 +fireresistanceexpotion,373,8259 +fireresistexpotion,373,8259 +fireresexpotion,373,8259 +fireresistanceextendedpot,373,8259 +fireresistextendedpot,373,8259 +fireresextendedpot,373,8259 +fireresistanceexpot,373,8259 +fireresistexpot,373,8259 +fireresexpot,373,8259 +fepot,373,8259 +poisonextendedpotion,373,8260 +acidextendedpotion,373,8260 +poisonexpotion,373,8260 +acidexpotion,373,8260 +poisonextendedpot,373,8260 +acidextendedpot,373,8260 +poisonexpot,373,8260 +acidexpot,373,8260 +pepot,373,8260 +nightvisionextendedpotion,373,8262 +nvisionextendedpotion,373,8262 +nightvextendedpotion,373,8262 +darkvisionextendedpotion,373,8262 +dvisionextendedpotion,373,8262 +darkvextendedpotion,373,8262 +nightvisionexpotion,373,8262 +nvisionexpotion,373,8262 +nightvexpotion,373,8262 +darkvisionexpotion,373,8262 +dvisionexpotion,373,8262 +darkvexpotion,373,8262 +nightvisionextendedpot,373,8262 +nvisionextendedpot,373,8262 +nightvextendedpot,373,8262 +darkvisionextendedpot,373,8262 +dvisionextendedpot,373,8262 +darkvextendedpot,373,8262 +nightvisionexpot,373,8262 +nvisionexpot,373,8262 +nightvexpot,373,8262 +darkvisionexpot,373,8262 +dvisionexpot,373,8262 +darkvexpot,373,8262 +nepot,373,8262 +weaknessextendedpotion,373,8264 +weakextendedpotion,373,8264 +weaknessexpotion,373,8264 +weakexpotion,373,8264 +weaknessextendedpot,373,8264 +weakextendedpot,373,8264 +weaknessexpot,373,8264 +weakexpot,373,8264 +wepot,373,8264 +strengthextendedpotion,373,8265 +strongextendedpotion,373,8265 +strextendedpotion,373,8265 +strengthexpotion,373,8265 +strongexpotion,373,8265 +strexpotion,373,8265 +strengthextendedpot,373,8265 +strongextendedpot,373,8265 +strextendedpot,373,8265 +strengthexpot,373,8265 +strongexpot,373,8265 +strexpot,373,8265 +stepot,373,8265 +slownessextendedpotion,373,8266 +slowextenedpotion,373,8266 +slownessexpotion,373,8266 +slowexpotion,373,8266 +slownessextendedpot,373,8266 +slowextenedpot,373,8266 +slownessexpot,373,8266 +slowexpot,373,8266 +slepot,373,8266 +waterbreathingextendedpotion,373,8269 +waterbreathextendedpotion,373,8269 +breathingextendedpotion,373,8269 +breathextendedpotion,373,8269 +waterbreathingextendedpot,373,8269 +waterbreathextendedpot,373,8269 +breathingextendedpot,373,8269 +breathextendedpot,373,8269 +waterbreathingexpotion,373,8269 +waterbreathexpotion,373,8269 +breathingexpotion,373,8269 +breathexpotion,373,8269 +waterbreathingexpot,373,8269 +waterbreathexpot,373,8269 +breathingexpot,373,8269 +breathexpot,373,8269 +wbepot,373,8269 +invisibilityextendedpotion,373,8270 +invisibleextendedpotion,373,8270 +invextendedpotion,373,8270 +invisibilityexpotion,373,8270 +invisibleexpotion,373,8270 +invexpotion,373,8270 +invisibilityextendedpot,373,8270 +invisibleextendedpot,373,8270 +invextendedpot,373,8270 +invisibilityexpot,373,8270 +invisibleexpot,373,8270 +invexpot,373,8270 +iepot,373,8270 +regenerationdualbitpotion,373,8289 +regeneratedualbitpotion,373,8289 +regendualbitpotion,373,8289 +regenerationdbpotion,373,8289 +regeneratedbpotion,373,8289 +regendbpotion,373,8289 +regenerationdualbitpot,373,8289 +regeneratedualbitpot,373,8289 +regendualbitpot,373,8289 +regenerationdbpot,373,8289 +regeneratedbpot,373,8289 +regendbpot,373,8289 +rdbpot,373,8289 +swiftnessdualbitpotion,373,8290 +swiftdualbitpotion,373,8290 +speeddualbitpotion,373,8290 +swiftnessdualbitpot,373,8290 +swiftdualbitpot,373,8290 +speeddualbitpot,373,8290 +swiftnessdbpotion,373,8290 +swiftdbpotion,373,8290 +speeddbpotion,373,8290 +swiftnessdbpot,373,8290 +swiftdbpot,373,8290 +speeddbpot,373,8290 +swdbpot,373,8290 +poisondualbitpotion,373,8292 +aciddualbitpotion,373,8292 +poisondualbitpot,373,8292 +aciddualbitpot,373,8292 +poisondbpotion,373,8292 +aciddbpotion,373,8292 +poisondbpot,373,8292 +aciddbpot,373,8292 +pdbpot,373,8292 +strengthdualbitpotion,373,8297 +strongdualbitpotion,373,8297 +strdualbitpotion,373,8297 +strengthdualbitpot,373,8297 +strongdualbitpot,373,8297 +strdualbitpot,373,8297 +strengthdbpotion,373,8297 +strongdbpotion,373,8297 +strdbpotion,373,8297 +strengthdbpot,373,8297 +strongdbpot,373,8297 +strdbpot,373,8297 +stdbpot,373,8297 +splashmundanepotion,373,16384 +splmundanepotion,373,16384 +splashregenerationpotion,373,16385 +splashregeneratepotion,373,16385 +splashregenpotion,373,16385 +splashregenerationpot,373,16385 +splashregeneratepot,373,16385 +splashregenpot,373,16385 +regenerationsplashpotion,373,16385 +regeneratesplashpotion,373,16385 +regensplashpotion,373,16385 +splregenerationpotion,373,16385 +splregeneratepotion,373,16385 +splregenpotion,373,16385 +splregenerationpot,373,16385 +splregeneratepot,373,16385 +splregenpot,373,16385 +sprpot,373,16385 +splashswiftnesspotion,373,16386 +splashswiftpotion,373,16386 +splashspeedpotion,373,16386 +splashswiftnesspot,373,16386 +splashswiftpot,373,16386 +splashspeedpot,373,16386 +splswiftnesspotion,373,16386 +splswiftpotion,373,16386 +splspeedpotion,373,16386 +splswiftnesspot,373,16386 +splswiftpot,373,16386 +splspeedpot,373,16386 +spswpot,373,16386 +splashfireresistancepotion,373,16387 +splashfireresistpotion,373,16387 +splashfirerespotion,373,16387 +splashfireresistancepot,373,16387 +splashfireresistpot,373,16387 +splashfirerespot,373,16387 +splfireresistancepotion,373,16387 +splfireresistpotion,373,16387 +splfirerespotion,373,16387 +splfireresistancepot,373,16387 +splfireresistpot,373,16387 +splfirerespot,373,16387 +spfpot,373,16387 +splashpoisonpotion,373,16388 +splashacidpotion,373,16388 +splashpoisonpot,373,16388 +splashacidpot,373,16388 +splpoisonpotion,373,16388 +splacidpotion,373,16388 +splpoisonpot,373,16388 +splacidpot,373,16388 +spppot,373,16388 +splashhealingpotion,373,16389 +splashhealpotion,373,16389 +splashlifepotion,373,16389 +splashhealingpot,373,16389 +splashhealpot,373,16389 +splashlifepot,373,16389 +splhealingpotion,373,16389 +splhealpotion,373,16389 +spllifepotion,373,16389 +splhealingpot,373,16389 +splhealpot,373,16389 +spllifepot,373,16389 +sphpot,373,16389 +splashclearpotion,373,16390 +splashclearpot,373,16390 +splclearpotion,373,16390 +splclearpot,373,16390 +splashnightvisionpotion,373,16390 +splashnvisionpotion,373,16390 +splashnightvpotion,373,16390 +splashdarkvisionpotion,373,16390 +splashdvisionpotion,373,16390 +splashdarkvpotion,373,16390 +splashnightvisionpot,373,16390 +splashnvisionpot,373,16390 +splashnightvpot,373,16390 +splashdarkvisionpot,373,16390 +splashdvisionpot,373,16390 +splashdarkvpot,373,16390 +splnightvisionpotion,373,16390 +splnvisionpotion,373,16390 +splnightvpotion,373,16390 +spldarkvisionpotion,373,16390 +spldvisionpotion,373,16390 +spldarkvpotion,373,16390 +splnightvisionpot,373,16390 +splnvisionpot,373,16390 +splnightvpot,373,16390 +spldarkvisionpot,373,16390 +spldvisionpot,373,16390 +spldarkvpot,373,16390 +spnpot,373,16390 +splashclearextendedpotion,373,16391 +splashclearexpotion,373,16391 +splashclear2potion,373,16391 +splashclearextendedpot,373,16391 +splashclearexpot,373,16391 +splashclear2pot,373,16391 +splclearextendedpotion,373,16391 +splclearexpotion,373,16391 +splclear2potion,373,16391 +splclearextendedpot,373,16391 +splclearexpot,373,16391 +splclear2pot,373,16391 +splashweaknesspotion,373,16392 +splashweakpotion,373,16392 +splashweaknesspot,373,16392 +splashweakpot,373,16392 +splweaknesspotion,373,16392 +splweakpotion,373,16392 +splweaknesspot,373,16392 +splweakpot,373,16392 +spwpot,373,16392 +splashstrengthpotion,373,16393 +splashstrongpotion,373,16393 +splashstrpotion,373,16393 +splashstrengthpot,373,16393 +splashstrongpot,373,16393 +splashstrpot,373,16393 +splstrengthpotion,373,16393 +splstrongpotion,373,16393 +splstrpotion,373,16393 +splstrengthpot,373,16393 +splstrongpot,373,16393 +splstrpot,373,16393 +spstpot,373,16393 +splashslownesspotion,373,16394 +splashslowpotion,373,16394 +splashslownesspot,373,16394 +splashslowpot,373,16394 +splslownesspotion,373,16394 +splslowpotion,373,16394 +splslownesspot,373,16394 +splslowpot,373,16394 +spslpot,373,16394 +splashdiffusepotion,373,16395 +splashdiffusepot,373,16395 +spldiffusepotion,373,16395 +spldiffusepot,373,16395 +splashharmingpotion,373,16396 +splashdamagepotion,373,16396 +splashdmgpotion,373,16396 +splashharmingpot,373,16396 +splashdamagepot,373,16396 +splashdmgpot,373,16396 +splharmingpotion,373,16396 +spldamagepotion,373,16396 +spldmgpotion,373,16396 +splharmingpot,373,16396 +spldamagepot,373,16396 +spldmgpot,373,16396 +spdpot,373,16396 +splashartlesspotion,373,16397 +splashartlesspot,373,16397 +splartlesspotion,373,16397 +splartlesspot,373,16397 +splashwaterbreathingpotion,373,16397 +splashwaterbreathpotion,373,16397 +splashbreathingpotion,373,16397 +splashbreathpotion,373,16397 +splashwaterbreathingpot,373,16397 +splashwaterbreathpot,373,16397 +splashbreathingpot,373,16397 +splashbreathpot,373,16397 +splwaterbreathingpotion,373,16397 +splwaterbreathpotion,373,16397 +splbreathingpotion,373,16397 +splbreathpotion,373,16397 +splwaterbreathingpot,373,16397 +splwaterbreathpot,373,16397 +splbreathingpot,373,16397 +splbreathpot,373,16397 +spwbpot,373,16397 +splashthinpotion,373,16398 +splashthinpot,373,16398 +splthinpotion,373,16398 +splthinpot,373,16398 +splashinvisibilitypotion,373,16398 +splashinvisiblepotion,373,16398 +splashinvpotion,373,16398 +splashinvisibilitypot,373,16398 +splashinvisiblepot,373,16398 +splashinvpot,373,16398 +splinvisibilitypotion,373,16398 +splinvisiblepotion,373,16398 +splinvpotion,373,16398 +splinvisibilitypot,373,16398 +splinvisiblepot,373,16398 +splinvpot,373,16398 +spipot,373,16398 +splashthinextendedpotion,373,16399 +splashthinexpotion,373,16399 +splashthin2potion,373,16399 +splashthinextendedpot,373,16399 +splashthinexpot,373,16399 +splashthin2pot,373,16399 +splthinextendedpotion,373,16399 +splthinexpotion,373,16399 +splthin2potion,373,16399 +splthinextendedpot,373,16399 +splthinexpot,373,16399 +splthin2pot,373,16399 +splashawkwardpotion,373,16400 +splashawkwardpot,373,16400 +splawkwardpotion,373,16400 +splawkwardpot,373,16400 +splashbunglingpotion,373,16406 +splashbunglingpot,373,16406 +splbunglingpotion,373,16406 +splbunglingpot,373,16406 +splashbunglingextendedpotion,373,16407 +splashbunglingexpotion,373,16407 +splashbungling2potion,373,16407 +splashbunglingextendedpot,373,16407 +splashbunglingexpot,373,16407 +splashbungling2pot,373,16407 +splbunglingextendedpotion,373,16407 +splbunglingexpotion,373,16407 +splbungling2potion,373,16407 +splbunglingextendedpot,373,16407 +splbunglingexpot,373,16407 +splbungling2pot,373,16407 +splashsmoothpotion,373,16411 +splashsmoothpot,373,16411 +splsmoothpotion,373,16411 +splsmoothpot,373,16411 +splashsuavepotion,373,16413 +splashsuavepot,373,16413 +splsuavepotion,373,16413 +splsuavepot,373,16413 +splashdebonairpotion,373,16414 +splashdebonairpot,373,16414 +spldebonairpotion,373,16414 +spldebonairpot,373,16414 +splashdebonairextendedpotion,373,16415 +splashdebonairexpotion,373,16415 +splashdebonair2potion,373,16415 +splashdebonairextendedpot,373,16415 +splashdebonairexpot,373,16415 +splashdebonair2pot,373,16415 +spldebonairextendedpotion,373,16415 +spldebonairexpotion,373,16415 +spldebonair2potion,373,16415 +spldebonairextendedpot,373,16415 +spldebonairexpot,373,16415 +spldebonair2pot,373,16415 +splashthickpotion,373,16416 +splashthickpot,373,16416 +splthickpotion,373,16416 +splthickpot,373,16416 +splashregenerationleveliipotion,373,16417 +splashregenerateleveliipotion,373,16417 +splashregenleveliipotion,373,16417 +splashregenerationlevel2potion,373,16417 +splashregeneratelevel2potion,373,16417 +splashregenlevel2potion,373,16417 +splashregenerationiipotion,373,16417 +splashregenerateiipotion,373,16417 +splashregeniipotion,373,16417 +splashregenerationleveliipot,373,16417 +splashregenerateleveliipot,373,16417 +splashregenleveliipot,373,16417 +splashregenerationlevel2pot,373,16417 +splashregeneratelevel2pot,373,16417 +splashregenlevel2pot,373,16417 +splashregenerationiipot,373,16417 +splashregenerateiipot,373,16417 +splashregeniipot,373,16417 +splregenerationleveliipotion,373,16417 +splregenerateleveliipotion,373,16417 +splregenleveliipotion,373,16417 +splregenerationlevel2potion,373,16417 +splregeneratelevel2potion,373,16417 +splregenlevel2potion,373,16417 +splregenerationiipotion,373,16417 +splregenerateiipotion,373,16417 +splregeniipotion,373,16417 +splregenerationleveliipot,373,16417 +splregenerateleveliipot,373,16417 +splregenleveliipot,373,16417 +splregenerationlevel2pot,373,16417 +splregeneratelevel2pot,373,16417 +splregenlevel2pot,373,16417 +splregenerationiipot,373,16417 +splregenerateiipot,373,16417 +splregeniipot,373,16417 +spr2pot,373,16417 +splashswiftnessleveliipotion,373,16418 +splashswiftleveliipotion,373,16418 +splashspeedleveliipotion,373,16418 +splashswiftnesslevel2potion,373,16418 +splashswiftlevel2potion,373,16418 +splashspeedlevel2potion,373,16418 +splashswiftnessiipotion,373,16418 +splashswiftiipotion,373,16418 +splashspeediipotion,373,16418 +splashswiftnessleveliipot,373,16418 +splashswiftleveliipot,373,16418 +splashspeedleveliipot,373,16418 +splashswiftnesslevel2pot,373,16418 +splashswiftlevel2pot,373,16418 +splashspeedlevel2pot,373,16418 +splashswiftnessiipot,373,16418 +splashswiftiipot,373,16418 +splashspeediipot,373,16418 +splswiftnessleveliipotion,373,16418 +splswiftleveliipotion,373,16418 +splspeedleveliipotion,373,16418 +splswiftnesslevel2potion,373,16418 +splswiftlevel2potion,373,16418 +splspeedlevel2potion,373,16418 +splswiftnessiipotion,373,16418 +splswiftiipotion,373,16418 +splspeediipotion,373,16418 +splswiftnessleveliipot,373,16418 +splswiftleveliipot,373,16418 +splspeedleveliipot,373,16418 +splswiftnesslevel2pot,373,16418 +splswiftlevel2pot,373,16418 +splspeedlevel2pot,373,16418 +splswiftnessiipot,373,16418 +splswiftiipot,373,16418 +splspeediipot,373,16418 +spsw2pot,373,16418 +splashpoisonleveliipotion,373,16420 +splashacidleveliipotion,373,16420 +splashpoisonlevel2potion,373,16420 +splashacidlevel2potion,373,16420 +splashpoisoniipotion,373,16420 +splashacidiipotion,373,16420 +splashpoisonleveliipot,373,16420 +splashacidleveliipot,373,16420 +splashpoisonlevel2pot,373,16420 +splashacidlevel2pot,373,16420 +splashpoisoniipot,373,16420 +splashacidiipot,373,16420 +splpoisonleveliipotion,373,16420 +splacidleveliipotion,373,16420 +splpoisonlevel2potion,373,16420 +splcidlevel2potion,373,16420 +splpoisoniipotion,373,16420 +splacidiipotion,373,16420 +splpoisonleveliipot,373,16420 +splacidleveliipot,373,16420 +splpoisonlevel2pot,373,16420 +splacidlevel2pot,373,16420 +splpoisoniipot,373,16420 +splacidiipot,373,16420 +spp2pot,373,16420 +splashhealingleveliipotion,373,16421 +splashhealleveliipotion,373,16421 +splashhealinglevel2potion,373,16421 +splashheallevel2potion,373,16421 +splashhealingiipotion,373,16421 +splashhealiipotion,373,16421 +splashhealingleveliipot,373,16421 +splashhealleveliipot,373,16421 +splashhealinglevel2pot,373,16421 +splashheallevel2pot,373,16421 +splashhealingiipot,373,16421 +splashhealiipot,373,16421 +splhealingleveliipotion,373,16421 +splhealleveliipotion,373,16421 +splhealinglevel2potion,373,16421 +splheallevel2potion,373,16421 +splhealingiipotion,373,16421 +splhealiipotion,373,16421 +splhealingleveliipot,373,16421 +splhealleveliipot,373,16421 +splhealinglevel2pot,373,16421 +splheallevel2pot,373,16421 +splhealingiipot,373,16421 +splhealiipot,373,16421 +sph2pot,373,16421 +splashcharmingpotion,373,16422 +splashcharmingpot,373,16422 +splcharmingpotion,373,16422 +splcharmingpot,373,16422 +splashcharmingextendedpotion,373,16423 +splashcharmingexpotion,373,16423 +splashcharming2potion,373,16423 +splashcharmingextendedpot,373,16423 +splashcharmingexpot,373,16423 +splashcharming2pot,373,16423 +splcharmingextendedpotion,373,16423 +splcharmingexpotion,373,16423 +splcharming2potion,373,16423 +splcharmingextendedpot,373,16423 +splcharmingexpot,373,16423 +splcharming2pot,373,16423 +splashstrengthleveliipotion,373,16425 +splashstrongleveliipotion,373,16425 +splashstrleveliipotion,373,16425 +splashstrengthlevel2potion,373,16425 +splashstronglevel2potion,373,16425 +splashstrlevel2potion,373,16425 +splashstrengthiipotion,373,16425 +splashstrongiipotion,373,16425 +splashstriipotion,373,16425 +splashstrengthleveliipot,373,16425 +splashstrongleveliipot,373,16425 +splashstrleveliipot,373,16425 +splashstrengthlevel2pot,373,16425 +splashstronglevel2pot,373,16425 +splashstrlevel2pot,373,16425 +splashstrengthiipot,373,16425 +splashstrongiipot,373,16425 +splashstriipot,373,16425 +splstrengthleveliipotion,373,16425 +splstrongleveliipotion,373,16425 +splstrleveliipotion,373,16425 +splstrengthlevel2potion,373,16425 +splstronglevel2potion,373,16425 +splstrlevel2potion,373,16425 +splstrengthiipotion,373,16425 +splstrongiipotion,373,16425 +splstriipotion,373,16425 +splstrengthleveliipot,373,16425 +splstrongleveliipot,373,16425 +splstrleveliipot,373,16425 +splstrengthlevel2pot,373,16425 +splstronglevel2pot,373,16425 +splstrlevel2pot,373,16425 +splstrengthiipot,373,16425 +splstrongiipot,373,16425 +splstriipot,373,16425 +spst2pot,373,16425 +splashrefinedpotion,373,16427 +splashrefinedpot,373,16427 +splrefinedpotion,373,16427 +splrefinedpot,373,16427 +splashharmingleveliipotion,373,16428 +splashdamageleveliipotion,373,16428 +splashdmgleveliipotion,373,16428 +splashharminglevel2potion,373,16428 +splashdamagelevel2potion,373,16428 +splashdmglevel2potion,373,16428 +splashharmingiipotion,373,16428 +splashdamageiipotion,373,16428 +splashdmgiipotion,373,16428 +splashharmingleveliipot,373,16428 +splashdamageleveliipot,373,16428 +splashdmgleveliipot,373,16428 +splashharminglevel2pot,373,16428 +splashdamagelevel2pot,373,16428 +splashdmglevel2pot,373,16428 +splashharmingiipot,373,16428 +splashdamageiipot,373,16428 +splashdmgiipot,373,16428 +splharmingleveliipotion,373,16428 +spldamageleveliipotion,373,16428 +spldmgleveliipotion,373,16428 +splharminglevel2potion,373,16428 +spldamagelevel2potion,373,16428 +spldmglevel2potion,373,16428 +splharmingiipotion,373,16428 +spldamageiipotion,373,16428 +spldmgiipotion,373,16428 +splharmingleveliipot,373,16428 +spldamageleveliipot,373,16428 +spldmgleveliipot,373,16428 +splharminglevel2pot,373,16428 +spldamagelevel2pot,373,16428 +spldmglevel2pot,373,16428 +splharmingiipot,373,16428 +spldamageiipot,373,16428 +spldmgiipot,373,16428 +spd2pot,373,16428 +splashcordialpotion,373,16429 +splashcordialpot,373,16429 +splcordialpotion,373,16429 +splcordialpot,373,16429 +splashsparklingpotion,373,16430 +splashsparklingpot,373,16430 +splsparklingpotion,373,16430 +splsparklingpot,373,16430 +splashsparklingextendedpotion,373,16431 +splashsparklingexpotion,373,16431 +splashsparkling2potion,373,16431 +splashsparklingextendedpot,373,16431 +splashsparklingexpot,373,16431 +splashsparkling2pot,373,16431 +splsparklingextendedpotion,373,16431 +splsparklingexpotion,373,16431 +splsparkling2potion,373,16431 +splsparklingextendedpot,373,16431 +splsparklingexpot,373,16431 +splsparkling2pot,373,16431 +splashpotentpotion,373,16432 +splashpotentpot,373,16432 +splpotentpotion,373,16432 +splpotentpot,373,16432 +splashrankpotion,373,16438 +splashrankpot,373,16438 +splrankpotion,373,16438 +splrankpot,373,16438 +splashrankextendedpotion,373,16439 +splashrankexpotion,373,16439 +splashrank2potion,373,16439 +splashrankextendedpot,373,16439 +splashrankexpot,373,16439 +splashrank2pot,373,16439 +splrankextendedpotion,373,16439 +splrankexpotion,373,16439 +splrank2potion,373,16439 +splrankextendedpot,373,16439 +splrankexpot,373,16439 +splrank2pot,373,16439 +splashacridpotion,373,16443 +splashacridpot,373,16443 +splacridpotion,373,16443 +splacridpot,373,16443 +splashgrosspotion,373,16445 +splashgrosspot,373,16445 +splgrosspotion,373,16445 +splgrosspot,373,16445 +splashstinkypotion,373,16446 +splashstinkypot,373,16446 +splstinkypotion,373,16446 +splstinkypot,373,16446 +splashstinkyextendedpotion,373,16447 +splashstinkyexpotion,373,16447 +splashstinky2potion,373,16447 +splashstinkyextendedpot,373,16447 +splashstinkyexpot,373,16447 +splashstinky2pot,373,16447 +splstinkyextendedpotion,373,16447 +splstinkyexpotion,373,16447 +splstinky2potion,373,16447 +splstinkyextendedpot,373,16447 +splstinkyexpot,373,16447 +splstinky2pot,373,16447 +splashmundaneextendedpotion,373,16448 +splashmundaneexpotion,373,16448 +splashmundane2potion,373,16448 +splashmundaneextendedpot,373,16448 +splashmundaneexpot,373,16448 +splashmundane2pot,373,16448 +splmundaneextendedpotion,373,16448 +splmundaneexpotion,373,16448 +splmundane2potion,373,16448 +splmundaneextendedpot,373,16448 +splmundaneexpot,373,16448 +splmundane2pot,373,16448 +splashregenerationextendedpotion,373,16449 +splashregenerateextendedpotion,373,16449 +splashregenextendepotion,373,16449 +splashregenerationexpotion,373,16449 +splashregenerateexpotion,373,16449 +splashregenexpotion,373,16449 +splashregenerationextendedpot,373,16449 +splashregenerateextendedpot,373,16449 +splashregenextendepot,373,16449 +splashregenerationexpot,373,16449 +splashregenerateexpot,373,16449 +splashregenexpot,373,16449 +splregenerationextendedpotion,373,16449 +splregenerateextendedpotion,373,16449 +splregenextendepotion,373,16449 +splregenerationexpotion,373,16449 +splregenerateexpotion,373,16449 +splregenexpotion,373,16449 +splregenerationextendedpot,373,16449 +splregenerateextendedpot,373,16449 +splregenextendepot,373,16449 +splregenerationexpot,373,16449 +splregenerateexpot,373,16449 +splregenexpot,373,16449 +sprepot,373,16449 +splashswiftnessextendedpotion,373,16450 +splashswiftextendedpotion,373,16450 +splashspeedextendedpotion,373,16450 +splashswiftnessexpotion,373,16450 +splashswiftexpotion,373,16450 +splashspeedexpotion,373,16450 +splashswiftnessextendedpot,373,16450 +splashswiftextendedpot,373,16450 +splashspeedextendedpot,373,16450 +splashswiftnessexpot,373,16450 +splashswiftexpot,373,16450 +splashspeedexpot,373,16450 +splswiftnessextendedpotion,373,16450 +splswiftextendedpotion,373,16450 +splspeedextendedpotion,373,16450 +splswiftnessexpotion,373,16450 +splswiftexpotion,373,16450 +splspeedexpotion,373,16450 +splswiftnessextendedpot,373,16450 +splswiftextendedpot,373,16450 +splspeedextendedpot,373,16450 +splswiftnessexpot,373,16450 +splswiftexpot,373,16450 +splspeedexpot,373,16450 +spswepot,373,16450 +splashfireresistanceextendedpotion,373,16451 +splashfireresistextendedpotion,373,16451 +splashfireresextendedpotion,373,16451 +splashfireresistanceexpotion,373,16451 +splashfireresistexpotion,373,16451 +splashfireresexpotion,373,16451 +splashfireresistanceextendedpot,373,16451 +splashfireresistextendedpot,373,16451 +splashfireresextendedpot,373,16451 +splashfireresistanceexpot,373,16451 +splashfireresistexpot,373,16451 +splashfireresexpot,373,16451 +splfireresistanceextendedpotion,373,16451 +splfireresistextendedpotion,373,16451 +splfireresextendedpotion,373,16451 +splfireresistanceexpotion,373,16451 +splfireresistexpotion,373,16451 +splfireresexpotion,373,16451 +splfireresistanceextendedpot,373,16451 +splfireresistextendedpot,373,16451 +splfireresextendedpot,373,16451 +splfireresistanceexpot,373,16451 +splfireresistexpot,373,16451 +splfireresexpot,373,16451 +spfepot,373,16451 +splashpoisonextendedpotion,373,16452 +splashacidextendedpotion,373,16452 +splashpoisonexpotion,373,16452 +splashacidexpotion,373,16452 +splashpoisonextendedpot,373,16452 +splashacidextendedpot,373,16452 +splashpoisonexpot,373,16452 +splashacidexpot,373,16452 +splpoisonextendedpotion,373,16452 +splacidextendedpotion,373,16452 +splpoisonexpotion,373,16452 +splacidexpotion,373,16452 +splpoisonextendedpot,373,16452 +splacidextendedpot,373,16452 +splpoisonexpot,373,16452 +splacidexpot,373,16452 +sppepot,373,16452 +splashnightvisionextendedpotion,373,16454 +splashnvisionextendedpotion,373,16454 +splashnightvextendedpotion,373,16454 +splashdarkvisionextendedpotion,373,16454 +splashdvisionextendedpotion,373,16454 +splashdarkvextendedpotion,373,16454 +splashnightvisionextendedpot,373,16454 +splashnvisionextendedpot,373,16454 +splashnightvextendedpot,373,16454 +splashdarkvisionextendedpot,373,16454 +splashdvisionextendedpot,373,16454 +splashdarkvextendedpot,373,16454 +splashnightvisionexpotion,373,16454 +splashnvisionexpotion,373,16454 +splashnightvexpotion,373,16454 +splashdarkvisionexpotion,373,16454 +splashdvisionexpotion,373,16454 +splashdarkvexpotion,373,16454 +splashnightvisionexpot,373,16454 +splashnvisionexpot,373,16454 +splashnightvexpot,373,16454 +splashdarkvisionexpot,373,16454 +splashdvisionexpot,373,16454 +splashdarkvexpot,373,16454 +splnightvisionextendedpotion,373,16454 +splnvisionextendedpotion,373,16454 +splnightvextendedpotion,373,16454 +spldarkvisionextendedpotion,373,16454 +spldvisionextendedpotion,373,16454 +spldarkvextendedpotion,373,16454 +splnightvisionextendedpot,373,16454 +splnvisionextendedpot,373,16454 +splnightvextendedpot,373,16454 +spldarkvisionextendedpot,373,16454 +spldvisionextendedpot,373,16454 +spldarkvextendedpot,373,16454 +splnightvisionexpotion,373,16454 +splnvisionexpotion,373,16454 +splnightvexpotion,373,16454 +spldarkvisionexpotion,373,16454 +spldvisionexpotion,373,16454 +spldarkvexpotion,373,16454 +splnightvisionexpot,373,16454 +splnvisionexpot,373,16454 +splnightvexpot,373,16454 +spldarkvisionexpot,373,16454 +spldvisionexpot,373,16454 +spldarkvexpot,373,16454 +spnepot,373,16454 +splashweaknessextendedpotion,373,16456 +splashweakextendedpotion,373,16456 +splashweaknessexpotion,373,16456 +splashweakexpotion,373,16456 +splashweaknessextendedpot,373,16456 +splashweakextendedpot,373,16456 +splashweaknessexpot,373,16456 +splashweakexpot,373,16456 +splweaknessextendedpotion,373,16456 +sphweakextendedpotion,373,16456 +splweaknessexpotion,373,16456 +splweakexpotion,373,16456 +splweaknessextendedpot,373,16456 +splweakextendedpot,373,16456 +splweaknessexpot,373,16456 +splweakexpot,373,16456 +spwepot,373,16456 +splashstrengthextendedpotion,373,16457 +splashstrongextendedpotion,373,16457 +splashstrextendedpotion,373,16457 +splashstrengthexpotion,373,16457 +splashstrongexpotion,373,16457 +splashstrexpotion,373,16457 +splashstrengthextendedpot,373,16457 +splashstrongextendedpot,373,16457 +splashstrextendedpot,373,16457 +splashstrengthexpot,373,16457 +splashstrongexpot,373,16457 +splashstrexpot,373,16457 +splstrengthextendedpotion,373,16457 +splstrongextendedpotion,373,16457 +splstrextendedpotion,373,16457 +splstrengthexpotion,373,16457 +splstrongexpotion,373,16457 +splstrexpotion,373,16457 +splstrengthextendedpot,373,16457 +splstrongextendedpot,373,16457 +splstrextendedpot,373,16457 +splstrengthexpot,373,16457 +splstrongexpot,373,16457 +splstrexpot,373,16457 +spstepot,373,16457 +splashslownessextendedpotion,373,16458 +splashslowextenedpotion,373,16458 +splashslownessexpotion,373,16458 +splashslowexpotion,373,16458 +splashslownessextendedpot,373,16458 +splashslowextenedpot,373,16458 +splashslownessexpot,373,16458 +splashslowexpot,373,16458 +splslownessextendedpotion,373,16458 +splslowextenedpotion,373,16458 +splslownessexpotion,373,16458 +splslowexpotion,373,16458 +splslownessextendedpot,373,16458 +splslowextenedpot,373,16458 +splslownessexpot,373,16458 +splslowexpot,373,16458 +spslepot,373,16458 +splashwaterbreathingextendedpotion,373,16461 +splashwaterbreathextendedpotion,373,16461 +splashbreathingextendedpotion,373,16461 +splashbreathextendedpotion,373,16461 +splashwaterbreathingextendedpot,373,16461 +splashwaterbreathextendedpot,373,16461 +splashbreathingextendedpot,373,16461 +splashbreathextendedpot,373,16461 +splwaterbreathingextendedpotion,373,16461 +splwaterbreathextendedpotion,373,16461 +splbreathingextendedpotion,373,16461 +splbreathextendedpotion,373,16461 +splwaterbreathingextendedpot,373,16461 +splwaterbreathextendedpot,373,16461 +splbreathingextendedpot,373,16461 +splbreathextendedpot,373,16461 +splashwaterbreathingexpotion,373,16461 +splashwaterbreathexpotion,373,16461 +splashbreathingexpotion,373,16461 +splashbreathexpotion,373,16461 +splashwaterbreathingexpot,373,16461 +splashwaterbreathexpot,373,16461 +splashbreathingexpot,373,16461 +splashbreathexpot,373,16461 +splwaterbreathingexpotion,373,16461 +splwaterbreathexpotion,373,16461 +splbreathingexpotion,373,16461 +splbreathexpotion,373,16461 +splwaterbreathingexpot,373,16461 +splwaterbreathexpot,373,16461 +splbreathingexpot,373,16461 +splbreathexpot,373,16461 +spwbepot,373,16461 +splashinvisibilityextendedpotion,373,16462 +splashinvisibleextendedpotion,373,16462 +splashinvextendedpotion,373,16462 +splashinvisibilityextendedpot,373,16462 +splashinvisibleextendedpot,373,16462 +splashinvextendedpot,373,16462 +splashinvisibilityexpotion,373,16462 +splashinvisibleexpotion,373,16462 +splashinvexpotion,373,16462 +splashinvisibilityexpot,373,16462 +splashinvisibleexpot,373,16462 +splashinvexpot,373,16462 +splinvisibilityextendedpotion,373,16462 +splinvisibleextendedpotion,373,16462 +splinvextendedpotion,373,16462 +splinvisibilityextendedpot,373,16462 +splinvisibleextendedpot,373,16462 +splinvextendedpot,373,16462 +splinvisibilityexpotion,373,16462 +splinvisibleexpotion,373,16462 +splinvexpotion,373,16462 +splinvisibilityexpot,373,16462 +splinvisibleexpot,373,16462 +splinvexpot,373,16462 +spiepot,373,16462 +splashregenerationdualbitpotion,373,16481 +splashregeneratedualbitpotion,373,16481 +splashregendualbitpotion,373,16481 +splashregenerationdualbitpot,373,16481 +splashregeneratedualbitpot,373,16481 +splashregendualbitpot,373,16481 +splregenerationdualbitpotion,373,16481 +splregeneratedualbitpotion,373,16481 +splregendualbitpotion,373,16481 +splregenerationdualbitpot,373,16481 +splregeneratedualbitpot,373,16481 +splregendualbitpot,373,16481 +splashregenerationdbpotion,373,16481 +splashregeneratedbpotion,373,16481 +splashregendbpotion,373,16481 +splashregenerationdbpot,373,16481 +splashregeneratedbpot,373,16481 +splashregendbpot,373,16481 +splregenerationdbpotion,373,16481 +splregeneratedbpotion,373,16481 +splregendbpotion,373,16481 +splregenerationdbpot,373,16481 +splregeneratedbpot,373,16481 +splregendbpot,373,16481 +sprdbpot,373,16481 +splashswiftnessdualbitpotion,373,16482 +splashswiftdualbitpotion,373,16482 +splashspeeddualbitpotion,373,16482 +splashswiftnessdualbitpot,373,16482 +splashswiftdualbitpot,373,16482 +splashspeeddualbitpot,373,16482 +splswiftnessdualbitpotion,373,16482 +splswiftdualbitpotion,373,16482 +splspeeddualbitpotion,373,16482 +splswiftnessdualbitpot,373,16482 +splswiftdualbitpot,373,16482 +splspeeddualbitpot,373,16482 +splashswiftnessdbpotion,373,16482 +splashswiftdbpotion,373,16482 +splashspeeddbpotion,373,16482 +splashswiftnessdbpot,373,16482 +splashswiftdbpot,373,16482 +splashspeeddbpot,373,16482 +splswiftnessdbpotion,373,16482 +splswiftdbpotion,373,16482 +splspeeddbpotion,373,16482 +splswiftnessdbpot,373,16482 +splswiftdbpot,373,16482 +splspeeddbpot,373,16482 +spswdbpot,373,16482 +splashpoisondualbitpotion,373,16484 +splashaciddualbitpotion,373,16484 +splashpoisondualbitpot,373,16484 +splashaciddualbitpot,373,16484 +splpoisondualbitpotion,373,16484 +splaciddualbitpotion,373,16484 +splpoisondualbitpot,373,16484 +splaciddualbitpot,373,16484 +splashpoisondbpotion,373,16484 +splashaciddbpotion,373,16484 +splashpoisondbpot,373,16484 +splashaciddbpot,373,16484 +splpoisondbpotion,373,16484 +splaciddbpotion,373,16484 +splpoisondbpot,373,16484 +splaciddbpot,373,16484 +sppdbpot,373,16484 +splashstrengthdualbitpotion,373,16489 +splashstrongdualbitpotion,373,16489 +splashstrdualbitpotion,373,16489 +splashstrengthdualbitpot,373,16489 +splashstrongdualbitpot,373,16489 +splashstrdualbitpot,373,16489 +splstrengthdualbitpotion,373,16489 +splstrongdualbitpotion,373,16489 +splstrdualbitpotion,373,16489 +splstrengthdualbitpot,373,16489 +splstrongdualbitpot,373,16489 +splstrdualbitpot,373,16489 +splashstrengthdbpotion,373,16489 +splashstrongdbpotion,373,16489 +splashstrdbpotion,373,16489 +splashstrengthdbpot,373,16489 +splashstrongdbpot,373,16489 +splashstrdbpot,373,16489 +splstrengthdbpotion,373,16489 +splstrongdbpotion,373,16489 +splstrdbpotion,373,16489 +splstrengthdbpot,373,16489 +splstrongdbpot,373,16489 +splstrdbpot,373,16489 +spstdbpot,373,16489 +glassbottle,374,0 +bottle,374,0 +gbottle,374,0 +gvase,374,0 +vase,374,0 +glassvase,374,0 +emptyglassbottle,374,0 +emptybottle,374,0 +emptygbottle,374,0 +emptygvase,374,0 +emptyvase,374,0 +emptyglassvase,374,0 +eglassbottle,374,0 +ebottle,374,0 +egbottle,374,0 +egvase,374,0 +evase,374,0 +eglassvase,374,0 +spidereye,375,0 +eyeofspider,375,0 +seye,375,0 +fermentedspidereye,376,0 +craftedspidereye,376,0 +fspidereye,376,0 +cspidereye,376,0 +fermentedeyeofspider,376,0 +craftedeyeofspider,376,0 +feyeofspider,376,0 +ceyeofspider,376,0 +fermentedseye,376,0 +craftedseye,376,0 +fseye,376,0 +cseye,376,0 +blazepowder,377,0 +blazedust,377,0 +goldpowder,377,0 +golddust,377,0 +gdust,377,0 +gpowder,377,0 +bpowder,377,0 +bdust,377,0 +magmacream,378,0 +goldcream,378,0 +blazecream,378,0 +mcream,378,0 +gcream,378,0 +bcream,378,0 +combinedcream,378,0 +ccream,378,0 +bstand,379,0 +pstand,379,0 +brewingstand,379,0 +potionstand,379,0 +cauldron,380,0 +steelcauldron,380,0 +ironcauldron,380,0 +icauldron,380,0 +scauldron,380,0 +potioncauldron,380,0 +pcauldron,380,0 +eyeofender,381,0 +endereye,381,0 +endeye,381,0 +evilendereye,381,0 +evileyeofender,381,0 +evilenderpearl,381,0 +eeye,381,0 +eofender,381,0 +glisteringmelon,382,0 +speckledmelon,382,0 +goldmelon,382,0 +sparklymelon,382,0 +shiningmelon,382,0 +gmelon,382,0 +smelon,382,0 +creeperegg,383,50 +eggcreeper,383,50 +skeletonegg,383,51 +eggskeleton,383,51 +spideregg,383,52 +eggspider,383,52 +giantegg,383,53 +egggiant,383,53 +zombieegg,383,54 +eggzombie,383,54 +slimeegg,383,55 +eggslime,383,55 +ghastegg,383,56 +eggghast,383,56 +zombiepigmanegg,383,57 +zpigmanegg,383,57 +pigmanegg,383,57 +zombiepmanegg,383,57 +zpmanegg,383,57 +zombiepigmegg,383,57 +zpigmegg,383,57 +zombiepigegg,383,57 +zpigegg,383,57 +zombiepmegg,383,57 +zombiepegg,383,57 +eggzombiepigman,383,57 +eggzpigman,383,57 +eggpigman,383,57 +eggzombiepman,383,57 +eggzpman,383,57 +eggzombiepigm,383,57 +eggzpigm,383,57 +eggzombiepig,383,57 +eggzpig,383,57 +eggzombiepm,383,57 +eggzombiep,383,57 +endermanegg,383,58 +eggenderman,383,58 +eggcavespider,383,59 +cavespideregg,383,59 +silverfishegg,383,60 +eggsilverfish,383,60 +blazeegg,383,61 +eggblaze,383,61 +lavaslimeegg,383,62 +lavacubeegg,383,62 +magmacubeegg,383,62 +magmaslimeegg,383,62 +egglavaslime,383,62 +egglavacube,383,62 +eggmagmacube,383,62 +eggmagmaslime,383,62 +bategg,383,65 +eggbat,383,65 +witchegg,383,66 +eggwitch,383,66 +pigegg,383,90 +eggpig,383,90 +sheepegg,383,91 +eggsheep,383,91 +cowegg,383,92 +eggcow,383,92 +chickenegg,383,93 +eggchicken,383,93 +squidegg,383,94 +eggsquid,383,94 +wolfegg,383,95 +eggwolf,383,95 +mooshroomegg,383,96 +mushroomcowegg,383,96 +eggmooshroom,383,96 +eggmushroomcow,383,96 +snowgolemegg,383,97 +sgolemegg,383,97 +eggsnowgolem,383,97 +eggsgolem,383,97 +ocelotegg,383,98 +eggocelot,383,98 +irongolemegg,383,99 +igolemegg,383,99 +eggirongolem,383,99 +eggigolem,383,99 +egghorse,383,100 +horseegg,383,100 +villageregg,383,120 +eggvillager,383,120 +bottleofenchanting,384,0 +enchantingbottle,384,0 +expbottle,384,0 +xpbottle,384,0 +bottleexp,384,0 +bottlexp,384,0 +enchantbottle,384,0 +bottleenchanting,384,0 +bottleenchant,384,0 +bottleoenchanting,384,0 +firecharge,385,0 +fireball,385,0 +grenade,385,0 +bookandquill,386,0 +booknquill,386,0 +bookandfeather,386,0 +booknfeather,386,0 +writeablebook,386,0 +writtenbook,387,0 +readablebook,387,0 +sealedbook,387,0 +diary,387,0 +ownedbook,387,0 +emerald,388,0 +itemframe,389,0 +pictureframe,389,0 +iframe,389,0 +pframe,389,0 +flowerpot,390,0 +pot,390,0 +carrot,391,0 +potato,392,0 +rawpotato,392,0 +bakedpotato,393,0 +roastedpotato,393,0 +cookedpotato,393,0 +bakepotato,393,0 +roastpotato,393,0 +cookpotato,393,0 +bpotato,393,0 +rpotato,393,0 +cpotato,393,0 +poisonouspotato,394,0 +poisonpotato,394,0 +ppotato,394,0 +emptymap,395,0 +map,395,0 +goldencarrot,396,0 +goldcarrot,396,0 +gcarrot,396,0 +head,397,0 +skull,397,0 +skeletonhead,397,0 +headskeleton,397,0 +skeletonskull,397,0 +skullskeleton,397,0 +witherhead,397,1 +witherskeletonhead,397,1 +wskeletionhead,397,1 +headwither,397,1 +headwitherskeleton,397,1 +headwskeletion,397,1 +witherskull,397,1 +witherskeletonskull,397,1 +wskeletionskull,397,1 +skullwither,397,1 +skullwitherskeleton,397,1 +skullwskeletion,397,1 +zombiehead,397,2 +headzombie,397,2 +zombieskull,397,2 +skullzombie,397,2 +playerhead,397,3 +humanhead,397,3 +stevehead,397,3 +headplayer,397,3 +headhuman,397,3 +headsteve,397,3 +playerskull,397,3 +humanskull,397,3 +steveskull,397,3 +skullplayer,397,3 +skullhuman,397,3 +skullsteve,397,3 +creeperhead,397,4 +headcreeper,397,4 +creeperskull,397,4 +skullcreeper,397,4 +carrotonastick,398,0 +carrotonstick,398,0 +netherstar,399,0 +hellstar,399,0 +nstar,399,0 +hstar,399,0 +star,399,0 +pumpkinpie,400,0 +pumpkincake,400,0 +ppie,400,0 +pcake,400,0 +pie,400,0 +fireworkrocket,401,0 +fireworkmissle,401,0 +firework,401,0 +fworkrocket,401,0 +fworkmissle,401,0 +fwork,401,0 +fwrocket,401,0 +fwmissle,401,0 +fireworkstar,402,0 +fworkstar,402,0 +fwstar,402,0 +fireworkball,402,0 +fworkball,402,0 +fwball,402,0 +fireworkpowder,402,0 +fworkpowder,402,0 +fwpowder,402,0 +fireworkcharge,402,0 +fworkcharge,402,0 +fwcharge,402,0 +enchantedbook,403,0 +enchantmentbook,403,0 +enchantingbook,403,0 +enchantbook,403,0 +magicalbook,403,0 +magicbook,403,0 +ebook,403,0 +mbook,403,0 +redstonecomparator,404,0 +redstonecomparer,404,0 +redstonecompare,404,0 +rstonecomparator,404,0 +rstonecomparer,404,0 +rstonecompare,404,0 +redscomparator,404,0 +redscomparer,404,0 +redscompare,404,0 +rscomparator,404,0 +rscomparer,404,0 +rscompare,404,0 +comparator,404,0 +comparer,404,0 +compare,404,0 +netherbrick,405,0 +nbrick,405,0 +hellbrick,405,0 +deathbrick,405,0 +dbrick,405,0 +hbrick,405,0 +netherquartz,406,0 +deathquartz,406,0 +hellquartz,406,0 +nquartz,406,0 +dquartz,406,0 +hquartz,406,0 +quartz,406,0 +tntminecart,407,0 +dynamiteminecart,407,0 +dynamitemcart,407,0 +dynamitecart,407,0 +bombminecart,407,0 +bombmcart,407,0 +bombcart,407,0 +tntmcart,407,0 +tntcart,407,0 +dminecart,407,0 +dmcart,407,0 +dcart,407,0 +bminecart,407,0 +bmcart,407,0 +bcart,407,0 +tminecart,407,0 +tmcart,407,0 +tcart,407,0 +hopperminecart,408,0 +hoppermcart,408,0 +hoppercart,408,0 +hopminecart,408,0 +hopmcart,408,0 +hopcart,408,0 +hminecart,408,0 +hmcart,408,0 +hcart,408,0 +ironhorsearmor,417,0 +ironharmor,417,0 +ironarmor,417,0 +ihorsearmor,417,0 +iharmor,417,0 +iarmor,417,0 +steelhorsearmor,417,0 +steelharmor,417,0 +steelarmor,417,0 +shorsearmor,417,0 +sharmor,417,0 +sarmor,417,0 +goldenhorsearmor,418,0 +goldenharmor,418,0 +goldenarmor,418,0 +goldhorsearmor,418,0 +goldharmor,418,0 +goldarmor,418,0 +ghorsearmor,418,0 +gharmor,418,0 +garmor,418,0 +diamondhorsearmor,419,0 +diamondharmor,419,0 +diamondarmor,419,0 +dhorsearmor,419,0 +dharmor,419,0 +darmor,419,0 +crystalhorsearmor,419,0 +crystalharmor,419,0 +crystalarmor,419,0 +chorsearmor,419,0 +charmor,419,0 +carmor,419,0 +lead,420,0 +leash,420,0 +rope,420,0 +nametag,421,0 +tag,421,0 +commandblockminecart,422,0 +cmdblockminecart,422,0 +cblockminecart,422,0 +commandminecart,422,0 +cmdminecart,422,0 +cbminecart,422,0 +commandblockcart,422,0 +cmdblockcart,422,0 +cblockcart,422,0 +commandcart,422,0 +cmdcart,422,0 +cbcart,422,0 +13disc,2256,0 +goldmusicrecord,2256,0 +goldmusicdisk,2256,0 +goldmusicdisc,2256,0 +goldmusiccd,2256,0 +13musicrecord,2256,0 +13musicdisk,2256,0 +13musicdisc,2256,0 +13musiccd,2256,0 +gomusicrecord,2256,0 +gomusicdisk,2256,0 +gomusicdisc,2256,0 +gomusiccd,2256,0 +goldmrecord,2256,0 +goldmdisk,2256,0 +goldmdisc,2256,0 +goldmcd,2256,0 +13mrecord,2256,0 +13mdisk,2256,0 +13mdisc,2256,0 +13mcd,2256,0 +gomrecord,2256,0 +gomdisk,2256,0 +gomdisc,2256,0 +gomcd,2256,0 +goldrecord,2256,0 +golddisk,2256,0 +golddisc,2256,0 +goldcd,2256,0 +13record,2256,0 +13disk,2256,0 +13cd,2256,0 +gorecord,2256,0 +godisk,2256,0 +godisc,2256,0 +gocd,2256,0 +record1,2256,0 +disk1,2256,0 +disc1,2256,0 +cd1,2256,0 +1record,2256,0 +1disk,2256,0 +1disc,2256,0 +1cd,2256,0 +catdisc,2257,0 +greenmusicrecord,2257,0 +greenmusicdisk,2257,0 +greenmusicdisc,2257,0 +greenmusiccd,2257,0 +catmusicrecord,2257,0 +catmusicdisk,2257,0 +catmusicdisc,2257,0 +catmusiccd,2257,0 +grmusicrecord,2257,0 +grmusicdisk,2257,0 +grmusicdisc,2257,0 +grmusiccd,2257,0 +greenmrecord,2257,0 +greenmdisk,2257,0 +greenmdisc,2257,0 +greenmcd,2257,0 +catmrecord,2257,0 +catmdisk,2257,0 +catmdisc,2257,0 +catmcd,2257,0 +grmrecord,2257,0 +grmdisk,2257,0 +grmdisc,2257,0 +grmcd,2257,0 +greenrecord,2257,0 +greendisk,2257,0 +greendisc,2257,0 +greencd,2257,0 +catrecord,2257,0 +catdisk,2257,0 +catcd,2257,0 +grrecord,2257,0 +grdisk,2257,0 +grdisc,2257,0 +grcd,2257,0 +record2,2257,0 +disk2,2257,0 +disc2,2257,0 +cd2,2257,0 +2record,2257,0 +2disk,2257,0 +2disc,2257,0 +2cd,2257,0 +blocksdisc,2258,0 +orangemusicrecord,2258,0 +orangemusicdisk,2258,0 +orangemusicdisc,2258,0 +orangemusiccd,2258,0 +blocksmusicrecord,2258,0 +blocksmusicdisk,2258,0 +blocksmusicdisc,2258,0 +blocksmusiccd,2258,0 +ormusicrecord,2258,0 +ormusicdisk,2258,0 +ormusicdisc,2258,0 +ormusiccd,2258,0 +orangemrecord,2258,0 +orangemdisk,2258,0 +orangemdisc,2258,0 +orangemcd,2258,0 +blocksmrecord,2258,0 +blocksmdisk,2258,0 +blocksmdisc,2258,0 +blocksmcd,2258,0 +ormrecord,2258,0 +ormdisk,2258,0 +ormdisc,2258,0 +ormcd,2258,0 +orangerecord,2258,0 +orangedisk,2258,0 +orangedisc,2258,0 +orangecd,2258,0 +blocksrecord,2258,0 +blocksdisk,2258,0 +blockscd,2258,0 +orrecord,2258,0 +ordisk,2258,0 +ordisc,2258,0 +orcd,2258,0 +record3,2258,0 +disk3,2258,0 +disc3,2258,0 +cd3,2258,0 +3record,2258,0 +3disk,2258,0 +3disc,2258,0 +3cd,2258,0 +chirpdisc,2259,0 +redmusicrecord,2259,0 +redmusicdisk,2259,0 +redmusicdisc,2259,0 +redmusiccd,2259,0 +chirpmusicrecord,2259,0 +chirpmusicdisk,2259,0 +chirpmusicdisc,2259,0 +chirpmusiccd,2259,0 +remusicrecord,2259,0 +remusicdisk,2259,0 +remusicdisc,2259,0 +remusiccd,2259,0 +redmrecord,2259,0 +redmdisk,2259,0 +redmdisc,2259,0 +redmcd,2259,0 +chirpmrecord,2259,0 +chirpmdisk,2259,0 +chirpmdisc,2259,0 +chirpmcd,2259,0 +remrecord,2259,0 +remdisk,2259,0 +remdisc,2259,0 +remcd,2259,0 +redrecord,2259,0 +reddisk,2259,0 +reddisc,2259,0 +redcd,2259,0 +chirprecord,2259,0 +chirpdisk,2259,0 +chirpcd,2259,0 +rerecord,2259,0 +redisk,2259,0 +redisc,2259,0 +recd,2259,0 +record4,2259,0 +disk4,2259,0 +disc4,2259,0 +cd4,2259,0 +4record,2259,0 +4disk,2259,0 +4disc,2259,0 +4cd,2259,0 +fardisc,2260,0 +lightgreenmusicrecord,2260,0 +lightgreenmusicdisk,2260,0 +lightgreenmusicdisc,2260,0 +lightgreenmusiccd,2260,0 +lgreenmusicrecord,2260,0 +lgreenmusicdisk,2260,0 +lgreenmusicdisc,2260,0 +lgreenmusiccd,2260,0 +lightgrmusicrecord,2260,0 +lightgrmusicdisk,2260,0 +lightgrmusicdisc,2260,0 +lightgrmusiccd,2260,0 +farmusicrecord,2260,0 +farmusicdisk,2260,0 +farmusicdisc,2260,0 +farmusiccd,2260,0 +lgrmusicrecord,2260,0 +lgrmusicdisk,2260,0 +lgrmusicdisc,2260,0 +lgrmusiccd,2260,0 +lightgreenmrecord,2260,0 +lightgreenmdisk,2260,0 +lightgreenmdisc,2260,0 +lightgreenmcd,2260,0 +lgreenmrecord,2260,0 +lgreenmdisk,2260,0 +lgreenmdisc,2260,0 +lgreenmcd,2260,0 +lightgrmrecord,2260,0 +lightgrmdisk,2260,0 +lightgrmdisc,2260,0 +lightgrmcd,2260,0 +farmrecord,2260,0 +farmdisk,2260,0 +farmdisc,2260,0 +farmcd,2260,0 +lgrmrecord,2260,0 +lgrmdisk,2260,0 +lgrmdisc,2260,0 +lgrmcd,2260,0 +lightgreenrecord,2260,0 +lightgreendisk,2260,0 +lightgreendisc,2260,0 +lightgreencd,2260,0 +lgreenrecord,2260,0 +lgreendisk,2260,0 +lgreendisc,2260,0 +lgreencd,2260,0 +lightgrrecord,2260,0 +lightgrdisk,2260,0 +lightgrdisc,2260,0 +lightgrcd,2260,0 +farrecord,2260,0 +fardisk,2260,0 +farcd,2260,0 +lgrrecord,2260,0 +lgrdisk,2260,0 +lgrdisc,2260,0 +lgrcd,2260,0 +record5,2260,0 +disk5,2260,0 +disc5,2260,0 +cd5,2260,0 +5record,2260,0 +5disk,2260,0 +5disc,2260,0 +5cd,2260,0 +malldisc,2261,0 +purplemusicrecord,2261,0 +purplemusicdisk,2261,0 +purplemusicdisc,2261,0 +purplemusiccd,2261,0 +mallmusicrecord,2261,0 +mallmusicdisk,2261,0 +mallmusicdisc,2261,0 +mallmusiccd,2261,0 +pumusicrecord,2261,0 +pumusicdisk,2261,0 +pumusicdisc,2261,0 +pumusiccd,2261,0 +purplemrecord,2261,0 +purplemdisk,2261,0 +purplemdisc,2261,0 +purplemcd,2261,0 +mallmrecord,2261,0 +mallmdisk,2261,0 +mallmdisc,2261,0 +mallmcd,2261,0 +pumrecord,2261,0 +pumdisk,2261,0 +pumdisc,2261,0 +pumcd,2261,0 +purplerecord,2261,0 +purpledisk,2261,0 +purpledisc,2261,0 +purplecd,2261,0 +mallrecord,2261,0 +malldisk,2261,0 +mallcd,2261,0 +purecord,2261,0 +pudisk,2261,0 +pudisc,2261,0 +pucd,2261,0 +record6,2261,0 +disk6,2261,0 +disc6,2261,0 +cd6,2261,0 +6record,2261,0 +6disk,2261,0 +6disc,2261,0 +6cd,2261,0 +mellohidisc,2262,0 +pinkmusicrecord,2262,0 +pinkmusicdisk,2262,0 +pinkmusicdisc,2262,0 +pinkmusiccd,2262,0 +mellohimusicrecord,2262,0 +mellohimusicdisk,2262,0 +mellohimusicdisc,2262,0 +mellohimusiccd,2262,0 +pimusicrecord,2262,0 +pimusicdisk,2262,0 +pimusicdisc,2262,0 +pimusiccd,2262,0 +pinkmrecord,2262,0 +pinkmdisk,2262,0 +pinkmdisc,2262,0 +pinkmcd,2262,0 +mellohimrecord,2262,0 +mellohimdisk,2262,0 +mellohimdisc,2262,0 +mellohimcd,2262,0 +pimrecord,2262,0 +pimdisk,2262,0 +pimdisc,2262,0 +pimcd,2262,0 +pinkrecord,2262,0 +pinkdisk,2262,0 +pinkdisc,2262,0 +pinkcd,2262,0 +mellohirecord,2262,0 +mellohidisk,2262,0 +mellohicd,2262,0 +pirecord,2262,0 +pidisk,2262,0 +pidisc,2262,0 +picd,2262,0 +record7,2262,0 +disk7,2262,0 +disc7,2262,0 +cd7,2262,0 +7record,2262,0 +7disk,2262,0 +7disc,2262,0 +7cd,2262,0 +staldisc,2263,0 +blackmusicrecord,2263,0 +blackmusicdisk,2263,0 +blackmusicdisc,2263,0 +blackmusiccd,2263,0 +stalmusicrecord,2263,0 +stalmusicdisk,2263,0 +stalmusicdisc,2263,0 +stalmusiccd,2263,0 +blmusicrecord,2263,0 +blmusicdisk,2263,0 +blmusicdisc,2263,0 +blmusiccd,2263,0 +blackmrecord,2263,0 +blackmdisk,2263,0 +blackmdisc,2263,0 +blackmcd,2263,0 +stalmrecord,2263,0 +stalmdisk,2263,0 +stalmdisc,2263,0 +stalmcd,2263,0 +blmrecord,2263,0 +blmdisk,2263,0 +blmdisc,2263,0 +blmcd,2263,0 +blackrecord,2263,0 +blackdisk,2263,0 +blackdisc,2263,0 +blackcd,2263,0 +stalrecord,2263,0 +staldisk,2263,0 +stalcd,2263,0 +blrecord,2263,0 +bldisk,2263,0 +bldisc,2263,0 +blcd,2263,0 +record8,2263,0 +disk8,2263,0 +disc8,2263,0 +cd8,2263,0 +8record,2263,0 +8disk,2263,0 +8disc,2263,0 +8cd,2263,0 +straddisc,2264,0 +whitemusicrecord,2264,0 +whitemusicdisk,2264,0 +whitemusicdisc,2264,0 +whitemusiccd,2264,0 +stradmusicrecord,2264,0 +stradmusicdisk,2264,0 +stradmusicdisc,2264,0 +stradmusiccd,2264,0 +whmusicrecord,2264,0 +whmusicdisk,2264,0 +whmusicdisc,2264,0 +whmusiccd,2264,0 +whitemrecord,2264,0 +whitemdisk,2264,0 +whitemdisc,2264,0 +whitemcd,2264,0 +stradmrecord,2264,0 +stradmdisk,2264,0 +stradmdisc,2264,0 +stradmcd,2264,0 +whmrecord,2264,0 +whmdisk,2264,0 +whmdisc,2264,0 +whmcd,2264,0 +whiterecord,2264,0 +whitedisk,2264,0 +whitedisc,2264,0 +whitecd,2264,0 +stradrecord,2264,0 +straddisk,2264,0 +stradcd,2264,0 +whrecord,2264,0 +whdisk,2264,0 +whdisc,2264,0 +whcd,2264,0 +record9,2264,0 +disk9,2264,0 +disc9,2264,0 +cd9,2264,0 +9record,2264,0 +9disk,2264,0 +9disc,2264,0 +9cd,2264,0 +warddisc,2265,0 +darkgreenmusicrecord,2265,0 +darkgreenmusicdisk,2265,0 +darkgreenmusicdisc,2265,0 +darkgreenmusiccd,2265,0 +dgreenmusicrecord,2265,0 +dgreenmusicdisk,2265,0 +dgreenmusicdisc,2265,0 +dgreenmusiccd,2265,0 +darkgrmusicrecord,2265,0 +darkgrmusicdisk,2265,0 +darkgrmusicdisc,2265,0 +darkgrmusiccd,2265,0 +wardmusicrecord,2265,0 +wardmusicdisk,2265,0 +wardmusicdisc,2265,0 +wardmusiccd,2265,0 +dgrmusicrecord,2265,0 +dgrmusicdisk,2265,0 +dgrmusicdisc,2265,0 +dgrmusiccd,2265,0 +darkgreenmrecord,2265,0 +darkgreenmdisk,2265,0 +darkgreenmdisc,2265,0 +darkgreenmcd,2265,0 +dgreenmrecord,2265,0 +dgreenmdisk,2265,0 +dgreenmdisc,2265,0 +dgreenmcd,2265,0 +darkgrmrecord,2265,0 +darkgrmdisk,2265,0 +darkgrmdisc,2265,0 +darkgrmcd,2265,0 +wardmrecord,2265,0 +wardmdisk,2265,0 +wardmdisc,2265,0 +wardmcd,2265,0 +dgrmrecord,2265,0 +dgrmdisk,2265,0 +dgrmdisc,2265,0 +dgrmcd,2265,0 +darkgreenrecord,2265,0 +darkgreendisk,2265,0 +darkgreendisc,2265,0 +darkgreencd,2265,0 +dgreenrecord,2265,0 +dgreendisk,2265,0 +dgreendisc,2265,0 +dgreencd,2265,0 +darkgrrecord,2265,0 +darkgrdisk,2265,0 +darkgrdisc,2265,0 +darkgrcd,2265,0 +wardrecord,2265,0 +warddisk,2265,0 +wardcd,2265,0 +dgrrecord,2265,0 +dgrdisk,2265,0 +dgrdisc,2265,0 +dgrcd,2265,0 +record10,2265,0 +disk10,2265,0 +disc10,2265,0 +cd10,2265,0 +10record,2265,0 +10disk,2265,0 +10disc,2265,0 +10cd,2265,0 +11disc,2266,0 +crackedmusicrecord,2266,0 +crackedmusicdisk,2266,0 +crackedmusicdisc,2266,0 +crackedmusiccd,2266,0 +crackmusicrecord,2266,0 +crackmusicdisk,2266,0 +crackmusicdisc,2266,0 +crackmusiccd,2266,0 +11musicrecord,2266,0 +11musicdisk,2266,0 +11musicdisc,2266,0 +11musiccd,2266,0 +cmusicrecord,2266,0 +cmusicdisk,2266,0 +cmusicdisc,2266,0 +cmusiccd,2266,0 +crackedmrecord,2266,0 +crackedmdisk,2266,0 +crackedmdisc,2266,0 +crackedmcd,2266,0 +crackmrecord,2266,0 +crackmdisk,2266,0 +crackmdisc,2266,0 +crackmcd,2266,0 +11mrecord,2266,0 +11mdisk,2266,0 +11mdisc,2266,0 +11mcd,2266,0 +cmrecord,2266,0 +cmdisk,2266,0 +cmdisc,2266,0 +cmcd,2266,0 +crackedrecord,2266,0 +crackeddisk,2266,0 +crackeddisc,2266,0 +crackedcd,2266,0 +crackrecord,2266,0 +crackdisk,2266,0 +crackdisc,2266,0 +crackcd,2266,0 +crecord,2266,0 +cdisk,2266,0 +cdisc,2266,0 +ccd,2266,0 +record11,2266,0 +disk11,2266,0 +disc11,2266,0 +cd11,2266,0 +11record,2266,0 +11disk,2266,0 +11cd,2266,0 +waitdisc,2267,0 +waitmusicrecord,2267,0 +waitmusicdisk,2267,0 +waitmusicdisc,2267,0 +waitmusiccd,2267,0 +bluemusicrecord,2267,0 +bluemusicdisk,2267,0 +bluemusicdisc,2267,0 +bluemusiccd,2267,0 +12musicrecord,2267,0 +12musicdisk,2267,0 +12musicdisc,2267,0 +12musiccd,2267,0 +cyanmusicrecord,2267,0 +cyanmusicdisk,2267,0 +cyanmusicdisc,2267,0 +cyanmusiccd,2267,0 +waitmrecord,2267,0 +waitmdisk,2267,0 +waitmdisc,2267,0 +waitmcd,2267,0 +bluemrecord,2267,0 +bluemdisk,2267,0 +bluemdisc,2267,0 +bluemcd,2267,0 +12mrecord,2267,0 +12mdisk,2267,0 +12mdisc,2267,0 +12mcd,2267,0 +cyanmrecord,2267,0 +cyanmdisk,2267,0 +cyanmdisc,2267,0 +cyanmcd,2267,0 +waitrecord,2267,0 +waitdisk,2267,0 +waitcd,2267,0 +bluerecord,2267,0 +bluedisk,2267,0 +bluedisc,2267,0 +bluecd,2267,0 +cyanrecord,2267,0 +cyandisk,2267,0 +cyandisc,2267,0 +cyancd,2267,0 +record12,2267,0 +disk12,2267,0 +disc12,2267,0 +cd12,2267,0 +12record,2267,0 +12disk,2267,0 +12disc,2267,0 +12cd,2267,0 +#9024e88d64262f1c5ea92df8399fa658 \ No newline at end of file diff --git a/bin/lives.yml b/bin/lives.yml new file mode 100644 index 0000000..04ec367 --- /dev/null +++ b/bin/lives.yml @@ -0,0 +1 @@ +lives: {} diff --git a/bin/locale.yml b/bin/locale.yml new file mode 100644 index 0000000..619f9fe --- /dev/null +++ b/bin/locale.yml @@ -0,0 +1,107 @@ +player_only: "&cOnly players may use that!" +no_permission: "&cNo permission." +player_unfound: "&e{0}&4 could not be found" +enabled: "&aEnabled" +disabled: "&cDisabled" +able: "&aAble" +unable: "&cUnable" +inventoryFull: "&cYou must clear your inventory first!" +notNumber: "&e{0} is not a number!" +angle_message: "&e{0} yaw&f, &e{1} pitch" +revive_cooldown: "&4You may not revive a player for another &e{0}4." +not_dead: "&e{0} &eis not deathbanned" +revived: "&aYou have revived &e{0}&a!" +revive_player: "&cYou revived {0}!" +revive_broadcast: "&c{0} revived {1}!" +selectEndPortal: "&cYou must select an end portal frame!" +locationSuccess: "&aSet location {0}" +firstLocationUnset: "&cYou must set the first location!" +portalTooBig: "&cYou cannot create a portal that big!" +portalElevation: "&cMake sure the portal is on the same elevation!" +portalSuccess: "&aCreated portal." +portalWandGive: "&aSelect 2 points to make an end portal" +noCooldown: "&4You do not have a Gopple cooldown active." +activeCooldown: "&eYour Gopple cooldown expires in {0}" +helpMenu: + - "&aThis is" + - "&aThe help menu" +userLocation: "&e{0}&a is in the area of {1} at coordinates: {2},{3},{4}" +logoutActive: "&aYour logout timer is already active!" +logoutStart: "&aYour logout timer is now active!" +pvpTimerNotActive: "&cYour {0} timer is currently not active." +pvpTimerDeactivate: "&cYour {0} timer has now been deactivated!" +pvpTimerActive: "&aYour {0} timer is still active for another {1}" +notInFaction: "&cYou are not in a faction!" +fullDTR: "&aYour faction has full DTR." +frozenDTR: "&aYour faction DTR is frozen for another {0}" +regeneratingDTR: "&aYour faction currently has {0} DTR and is regenerating at a rate of {1} every {2}. Estimated time until full DTR is {3}." +serverTime: "&aThe server time is {0}" +cannonOnlyOverworld: "&aYou can only " +toggleCapZoneMessages: "&eYou are now {0} to see cap zone entry messages" +toggleFDMessages: "&e{0} &ahas toggled &bFound Diamond Alerts" +toggleLSMessages: "&eYou will now be {0} to see Lightning Strikes on player deaths" + +# Scoreboard toggle +toggleScoreboard: "&eYou have now {0} your scoreboard" + +# Lives and deathban messages +noLivesInDB: "&eThere are no lives in the database!" +eotwDeathBanJoin: "&cYou are deathbanned for the rest of the map due to EOTW." +deathbanTimer: "&cYou are still deathbanned for {0}" +lifeUsed: "&aYou have used a life! You now have {0} lives." +noLives: "&cYou have no lives!" +deathbanWithLives: "&cYou are still deathbanned with {0} remaining! You can use a life by joining within {1}" +deathbanBypass: "&aYou would be deathbanned, but you have permission to bypass." +playerLifeCheck: "&e{0} currently has {1} lives" +notDeathbanned: "&e{0} is not deathbanned!" +deathbanReason: + - "&eDeathban caused by {0}" + - "&eTime: {1}" + - "&eDuration: {2}" +deathbanLocation: "&eLocation: ({0},{1},{2})" +deathbanReason: "&eReason: [{0}]" +clearDeathbanMessaage: "&eAll deathbans have been cleared" +livesMustBePositive: "&cThe amount of lives must be positive" +livesGiftFailure: "&cYou could not give {0} {1} live(s) because you only have {2}." +livesGiftSuccess: "&aYou gifted {0} with {1} live(s)" +livesGiftSuccessPlayer: "&e{0} gifted you with {1} live(s)" +livesReviveKitmap: "&eYou cannot revive players during kitmap!" +livesReviveEOTW: "&eYou cannot revive players during EOTW!" +lifeUsedOnOther: "&eYou have used a life to revive {0}" +livesConsoleRevive: "&eYou have revived {0}" +livesSet: "&e{0} now has {1} lives." +deathbanDurationError: "&cInvalid duration! Use format &o1h 2m" +deathbanDurationSet: "&eDeathban time has now been set to {0}!" +topLivesTitle: "&eTop {0} lives:" +topLivesFormat: "&e{0} {1}: {2}" +ecoGiveAll: "&e{0} gave all players ${1}" +ecoBalance: "&eYour balance: {0}" +ecoBalanceOther: "&e{0}'s balance: {1}" +ecoAdded: "&eAdded {0} to {1}'s balance. Their new balance is {2}" +ecoTaken: "&eTaken {0} from {1}'s balance. Their new balance is {2}" +ecoSet: "&eSet balance of {0} to {1}" +ecoNotPositive: "&cYou must send money in positive amounts." +ecoSendFailure: "&cYou tried to pay {0}, but you only have {1} in your account." +ecoSendSuccess: "&aYou have sent {0} to {1}" +ecoSendSuccessPlayer: "&a{0} sent you {1}" +notPlayerFaction: "&cThat faction could not be found or is not a player faction." +noEvents: "&cThere are no running events!" +eventCancelled: "&c{0} has cancelled the event {1}" +eventCreateNameUsed: "&cThere is already an event faction named {0}" +eventCreateSuccess: "&aCreated event faction {0} with event type {1}!" +eventDeleteNameUnused: "&cThere is no such event faction called {0}" +eventDeleteSuccess: "&aDeleted event faction {0}!" +eventRenameSuccess: "&aRenamed event {0} to {1}" +noWorldEdit: "&cYou need WorldEdit installed to use this feature!" +requireWorldEditSelection: "&cPlease make a WorldEdit selection!" +areaTooSmall: "&cRegion selection must be {0} x {0}" +eventAreaSuccess: "&aUpdated the claim area for event {0}" +eventStarted: "&aEvent has been started!" +eventUptime: "&aEvent &e({0})&a has been live for &e{1}&a and started at &e{2}" +conquestSetPointsError: "&cMaximum points for Conquest is {0}" +conquestSetPoints: "&aSet points for {0} to {1}" +noKeyFound: "&cNo key type named {0}" +keyOnlyPositive: "&cYou can only give keys in positive quantities" +keyMaximumAllowed: "&cYou cannot give keys in more than {0}'s" +keyGiven: "&cGiven {0}x {1} key to {2}" +crateClosedDuring: "&aYou closed your crate reward inventory, dropping your items on the ground!" \ No newline at end of file diff --git a/bin/plugin.yml b/bin/plugin.yml new file mode 100644 index 0000000..67eb09f --- /dev/null +++ b/bin/plugin.yml @@ -0,0 +1,130 @@ +name: Zorex +version: 1.0 +description: HCF CORE +author: bruceboy +main: me.bruce.factions.LorexHCF +softdepend: [ProtocolLib] +commands: + hcf: + rawcast: + wb: + nv: + stats: + setnpc: + staffguide: + tablistgui: + aliases: [tabgui] + coords: + pots: + vanish: + aliases: [v] + staffgui: + author: + aliases: [dev,developer,best,bestdev] + gamemode: + aliases: [gm] + setprefix: + slowchat: + disablechat: + tp: + here: + fly: + fix: + invsee: + randomtp: + panic: + tl: + baller: + rules: + vip: + zorex: + spawn: + lff: + pro: + prefix: + keysale: + sp: + fr: + reboot: + rank: + broadcast: + aliases: [bc] + buy: + tablist: + aliases: [pot] + settings: + refund: + aliases: [inv, restore, invrestore] + ping: + freeze: + aliases: [ss] + enderdragon: + hub: + this: + playtime: + aliases: [pt] + cobble: + crowgive: + aliases: [crowbar, crowbargive] + Amethyst: + hcfhelp: + aliases: [help, ehelp, pl, ?] + conquest: + description: Command used to handle Conquest events. + economy: + aliases: [$, bal, money, eco, econ] + description: Command used to modify the economy. + eotw: + aliases: [endoftheworld] + description: Sets if the server is in End of the World mode. + event: + description: Command used to manage minigame events. + faction: + aliases: [f, fac] + description: Faction related commands. + gopple: + description: Command to check remaining OP apple cooldown time. + aliases: [opple, goppletimer, goppletime, oppletimer, oppletime] + hcf: + aliases: [hardcorefactions, hcfactions] + koth: + description: Make or delete KotH arenas. + lives: + description: Management of lives or deathbans. + location: + aliases: [loc] + description: Check the faction location of a player. + logout: + aliases: [disconnect] + description: Command to safely logout without an NPC spawning. + mapkit: + aliases: [viewkit] + description: Used to check the current map restrictions. + pay: + aliases: [p2p] + description: Allow players to pay money. + pvptimer: + aliases: [pvp] + description: Command to enable or disable pvp timer protection. + regen: + description: Check ETA until a faction is able to regenerate DTR. + sotw: + aliases: [startoftheworld] + description: Command used to manage start of the world. + staffrevive: + aliases: [revive] + description: Command used by staff to revive players. + timer: + description: Command to manage timers. + togglecapzoneentry: + aliases: [togglecapentry] + description: Command used to hide or show capture zone entry messages. + togglelightning: + aliases: [lightningtoggle, togglestrikes] + description: Toggles the lightning strikes for when a player dies. + rename: + ores: + description: See ores mined. + aliases: [stats, mined] + glowstonemountain: + aliases: [reset] \ No newline at end of file diff --git a/bin/settings.yml b/bin/settings.yml new file mode 100644 index 0000000..4bb0deb --- /dev/null +++ b/bin/settings.yml @@ -0,0 +1,75 @@ +disable_obsidian_generators: true +server_time_zone: EST +warzone_radius: 650 +donate_url: store.Vengeful.us +spawn_buffer: 128 +map_number: 1 +disallowed_faction_names: +- Venge +- Vengeful +enchantment_limits: + PROTECTION_ENVIRONMENTAL: 2 + DAMAGE_ALL: 1 + ARROW_KNOCKBACK: 0 + KNOCKBACK: 0 + FIRE_ASPECT: 0 + THORNS: 0 + ARROW_FIRE: 1 + ARROW_DAMAGE: 3 +potion_limits: + STRENGTH: 1 + WEAKNESS: 0 + SLOWNESS: 0 + INVISIBILITY: 0 + POISON: 0 +road_lengths: + NORMAL: 4000 + NETHER: 4000 +border_sizes: + NORMAL: 2000 + NETHER: 2000 + THE_END: 1500 +spawn_radius_map: + NORMAL: 50 + NETHER: 25 + THE_END: 15 +diamond_ore_alerts: false +subclaim_name_characters_min: 3 +subclaim_name_characters_max: 16 +faction_name_characters_min: 3 +faction_name_characters_max: 16 +max_members_per_faction: 8 +road_distance: 2500 +road_min_height: 0 +road_max_height: 256 +end_portal_radius: 20 +end_portal_center: 750 +default_deathban_duration: 3600000 +kit_map: true +#Tablist is currently weird for 1.8 users use if you want +tablist: false +teammate_colour: DARK_GREEN +ally_colour: LIGHT_PURPLE +enemy_colour: RED +safezone_colour: AQUA +road_colour: GOLD +warzone_colour: RED +wilderness_colour: GREEN +scoreboard_title: '(Speed)' +max_allies_per_faction: 0 +max_claims_per_faction: 8 +allow_claiming_besides_roads: false +dtr_millis_between_updates: 45000 +dtr_increment_between_updates: 0.1 +maximum_dtr: 6.0 +exp_multiplier_general: 2.0 +exp_multiplier_fishing: 2.0 +exp_multiplier_smelting: 2.0 +exp_multiplier_looting_per_level: 6.0 +exp_multiplier_luck_per_level: 1.5 +exp_multiplier_fortune_per_level: 1.5 +conquest_point_loss_per_death: 30 +conquest_required_win_points: 300 +found_diamonds_alerts: true +combat_log_despawn_ticks: 600 +combat_log_prevention_enabled: true diff --git a/bin/timers.yml b/bin/timers.yml new file mode 100644 index 0000000..e69de29 diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..65a5faf --- /dev/null +++ b/config.yml @@ -0,0 +1,87 @@ +death-signs: true +diamond-ore-notifications: true +death-lightning: true +map-number: 1 +kit-map: true +prevent-ally-damage: true +exp-multiplier: + global: 2.0 + fishing: 2.0 + smelting: 2.0 + looting-per-level: 1.5 + luck-per-level: 1.5 + fortune-per-level: 1.5 +roads: + allow-claims-besides: true +scoreboard: + sidebar: + title: "" + enabled: true + nametags: + enabled: true +combatlog: + enabled: true + despawn-delay-ticks: 600 +conquest: + point-loss-per-death: 20 + victory-points: 300 + allow-negative-points: true +warzone: + radius: 1000 +factions: + disallowed-faction-names: + - EOTW + min-name-characters: 3 + max-name-characters: 16 + max-members: 25 + max-allies: 1 +subclaims: + min-name-characters: 3 + max-name-characters: 16 +relation-colours: + wilderness: DARK_GREEN + warzone: LIGHT_PURPLE + teammate: GREEN + ally: GOLD + enemy: RED + road: GOLD +deaths-till-raidable: + maximum: 6 + millis-between-updates: 45000 + increment-between-updates: 0.1 +deathban: + base-duration-minutes: 120 + respawn-screen-seconds-before-kick: 15 +enchantment-limits: + PROTECTION_ENVIRONMENTAL: 3 + PROTECTION_FIRE: 3 + SILK_TOUCH: 1 + DURABILITY: 3 + PROTECTION_EXPLOSIONS: 3 + LOOT_BONUS_BLOCKS: 3 + PROTECTION_PROJECTILE: 3 + OXYGEN: 3 + WATER_WORKER: 1 + THORNS: 0 + DAMAGE_ALL: 3 + ARROW_KNOCKBACK: 1 + KNOCKBACK: 1 + FIRE_ASPECT: 1 + LOOT_BONUS_MOBS: 3 + LUCK: 3 + LURE: 3 +end: + open: true + exit: world,0.5,75,0.5,0,0 +eotw: + chat-symbol-prefix: "" + chat-symbol-suffix: "" + last-map-cappers: [] +potion-limits: + STRENGTH: 0 + INVISIBILITY: 0 + REGEN: 0 + WEAKNESS: 0 + INSTANT_DAMAGE: 0 + SLOWNESS: 1 + POISON: 1 diff --git a/coords.txt b/coords.txt new file mode 100644 index 0000000..e69de29 diff --git a/enderdragon-art-old.png b/enderdragon-art-old.png new file mode 100644 index 0000000000000000000000000000000000000000..e33ffd6a2e19d287758323f1acfccbd684e08fc8 GIT binary patch literal 3117 zcmY*bc{tly7yiYsO)QBrq)}_AsZzC6f~X;uRv21El@gRzOVqAoms$p~rCLQxrB#Mn zhOtc-ODv_EA|bJjT~KSq(nb2E-^}+s^Zjw}J?Gx%p67keJ@0)_s_hvIgs`+Q000O} zg1H@kC4V1+0{q$9b-RGSKtk*+Oo8fN*+ssy@2ZK72>{e)iG01ZpYIC=5}ZQ-K(yog zfOH3xT?PP=c1v>;hj6!*!Vms3-N^3b>?CRl5`}Gh0EW9zZwvbxdu&2o(jOFXRA+BmPP_V|b zIfXpWT#CswVrv~)c^VZ$7a zgO+%i1;eenf1Q=OlWAg9WPGv}{d(?1ZinDY3A$6oAS}t0x7>~+;ekCy6EyKr+~*;( zE%&T38;BGKRsEGsVj`y$onsDfY>BKYv>yRy1-MGOb{S?q5=T`HPpiW1E+!2;q${p? zBKp$ZsMzJHFG5t20>g-pd&=S6ov9KkPX>M8?OS@Nvl4i%>t`*34>E;uVycYw;b;!U z@!?7ms1)tq<#~xW25W&%*6d_^`1@yCIpTJqJ;LR#NIyy=N>tVp5m*Zit${j$0yWS? z(_?P&CRPH|^^@94gpJaI4-xv6k;B7Oj}ti+@izV2 z?KjP8LZ7e5QM#rD;B7k2`Otw>{F)^aL-02P*D9?_PB286YS5DNXn$AM0cL_-`8DK- zoBl|EP~odruXL_*h#=a6xP!0r1XZ1DQRyn4z!Ce_L#O5716EUcg@q-Q^Ge+0OfL2P z*$4UV3*O`c6fA{WApA1U9BSLIw(-RaA^1{SjEqGCBs?k}LD-jVPY*|dkpj)7tC3Ww z)We+i{&8~N?06l`91(c^JRSY2+{4fW)L$nLz-OMt(&U%pDck6#p<^p|Ll?G%+6c{V z-7K-p=(M0e38=BHm~|cK^%CKDs?NsVCK1{qffU|vfV=Q;&c?R?d5`$hgUKTg1!kU# z5~&+HWUf@7(s`uDfZSV-hoLH1Hm4T2zqwTJu~lw1W|rof=C%CZ1VcWI+@=HSj};Mu zLi01{s=I3W5Aa9{SqagQQvB&xEU>w8lr?RRA)7^}e+(TK%Lxv8VyliqoI3$KUL60& z4;a8snh5WEU7Y7R>SIyvT0qxBU>p&@h<&?405J=kcn>nBQ)D1mM>@y1#9-!LrG24x zoOUPe)x=`({;1+E2R^Kry?s5a#mbS*uo1FW+|+T_(yFPNRK?5+fw)5!ecD|%nHVl# z1kA1r=!Vl%#?oI-CI-f?VFJp67!fg}&Jw+)(lX(1^#ge3A={6_7(uZgWZ%j459Mf< z&S@xSAC<=YTFsLc?akY0s5O5$wh4yqt5%)VZ8s-9P-JN0W_$eZDd{s`~=VZ-@o6={-Q&a0G+lENrXQ`T|wh?n&Pa&55)oNUFHz2Q@7lkdG9HQPj@-RURF0=%5YWu`S^uY4X?$*LFM$ITeF&VOBF74ELy zO9(Lu8r!>H=VlA1UWnM!dl*xj>j|yuVVB1~HR3 z^a8}#W-mX<-A2}adVmN&Gy)`Y$uQl<#zz!&T~_X2ewwY~9sZWgFGM9N{OCG);(F$l ziz`YrISRVCd^zggM??$_2$KGU=0Gv0-`U`i|&%r zs+#dLy4CfoDMNY>XGr}cf3C_e3=TU5KX4sc+&XZnX#$?^B_cgQ)@zbodz7*@H?;Iy z^I#VHMM(;}F}Dz=U@Z4~Yg0liPr|rT-{nofy5mY`$V%mjT$0?<-Y>4Mpv{%2qJyRKbZP)mo+#lx|&sPw){c3_al)=ey0^8bWt zLRyT%TXX?U`;B9|08wu=QX+*a+p&Zi|0cH**NVQV^50PZl1RZ8ck0(ayC6!+-8G*> zEeE9gl3JEr!1%=qKJL7K%-9;p=~=q0l@4E8eV}}}@4idvAwDWh0$)kJzl*JW{2EF* zi>a0QOTKk5yh34JXuTrbYRe!=5=-FdN!vy2pd1wn#eIJCBjL(M-GH z=s5fO_y-XS0}4h(u^NQZ4l@g#Uz3w995ShLjC3bm8-e^{pSol-!LT)5I=X^x4zJsjx$!0 zp^Y!Mhu38?+d1BHL*zYS68`li1OX>n3X#Gn&FO0aIS~;b5VXv)9{<3jD~gk)G2C>; zIsMYJZR?}HK-=B&!)kxX$XZ49JZFJl5!B=)7&fCKJ^esd*3}6|Fx|Z~GQK)xDj(Y> zP4#sG?L_|~Kuk4Gpay@I_DALGYd0<%-j8xY zlyP@A9b}&=c_V6|kNF_)bVyT!`LQw+Jb+~HBxp|mB1fZGU;N$t17XescK>uWd-z#x z-P35T>4DzQn!mJMI>mF*k3-66;cvJewgeZhuR)+5FI4)1A~|a(?#kWonQui_X+j%$ zMm6K9Z?{pNUwG3)&6}y6jc2bhzRujPdaiJN&xS_$k#{R%n?paTbZqvE&w)=kJj{o4 z?%^oQOi=DO?E@b}#N-zXP6s{7D^G#gr`$^PWUAErjC)yME=6c#3Vm9g5q*tbHCa0% z@h=XB6Y%mP^$phC%B)YNXx!p7pU=ws7;{w0lwPOA@_dLM#o&?wQufzrE)zb6R(e*~R0G`r#x$ev1!So;qV*ZR!#KAB?!i AdH?_b literal 0 HcmV?d00001 diff --git a/enderdragon-art.png b/enderdragon-art.png new file mode 100644 index 0000000000000000000000000000000000000000..31c18b3ac0a3f880a585628b24e5ad99c5e717af GIT binary patch literal 3142 zcmZXWc{G%5AII-8nF(V|DaJlMRFY*ZQ6e*g>>4VBG>mnSF($m$$q+HtL>_yhq|`h} zWX~32>`RG4OtNK9^iI#)Iq&w_6H!{?- z1rz)a-(;mFN-=OG(j@dE&O)2{(KENe{Th)Alw4fUdr zD>cB8;sTHzJ+4y~ue(rDYKmyZQ!Y^|E&#ySY@~<16zH&!?d>Nxe7J3RTKXvn9G2px zZIg0z^axK#WP~?L^})!kBqvGSn92gRC^vs1Pt{wqKfoK;q+8?z($URe#~no7O{(2} zwwPS8ne(cT6fkpRdG{?gd9iAzem1Ax+3JcL@vd>y5Ikgh&bzuc;!_mPg(9 zZTm-4l*!P*z@Z#pv?Sjz&Dk&k%Wh8+r}rIbcUJLR<+IAiPg0PLf%5L2r@o^y-*ze3 zqaoD%@b9fO%-V$sBqC;y9iTyT(8I)d-nPhf2#m45W!-kU*lre~4HD_k&3 zTgaz!Q}p9OIZpj9?!k?;{S(%T>Dl$<-eEv|!&khkyW8@O3UmUnICA$S-K=*b;-)SG zq}WPRZv}`LVFu_XK315J)Ti>d@&@Q0Epz*br9M|TZ#q392^Bl9-Pox9$R1*;W^|sa zj=E<$(?PgcUQ3un$d7vkXWA=P0^nuSOGPxQJS*4|!hi4`zTs@iB{{QAu8LT!he(X) z@H%)s?~5<1rQ1X5L1 z^%B!GW{;IDsgm(#b(Jq0hFHB197ws-xYg4R$k`qX3TJ@El_AtdB#WDffmVwl_+*aL zSKyGfeL-g9>nIotcapoH40PblOE)Z2baG6Nj^%tE$bgV1L4_h?H+C`FBix4as$}PdHRo4>>sG!>uC(Mhu}M1CV7L*d<-+-M^D6HnL-Bda_R1X zf$Ud0$i@(hL?F7_3T)ztFf=4mUls|rN8^HEMBww3#gi5u4O2F_P1^1lZd7Q6H%52r(SF?f#AbvXU2OpZ-j3Cg^&3t`Ms=S4i zVy%TgpIGJ$g)2Abbx%0uN7nW_sSHpu>cY76HZ2a;egJ!8=IWP)_$C1c|AKk?hDN`?27fZ`r&ty`(CVd-5x24~X#PzXCxY^{X7{AXrS(NcA58R)~Cnn5iaUn^&grs>#dW2xB{)>smvNb z+dV{?vgs%)?OZy>4=f8kI<%h;ESF%7GQbBWRw6-wHwnat{~#hKae z+XGBG5mROJuc<|oQopK=>6)H82+6au@J&p7;dr!gW#SSYR1$aNMA{e6;V%<5>r2xw z6WgTM*Olf=tRHN9Hqq8VDtVSqYG!t9OLfj%`)T#z(1K@PU6@@?jm?DphtR+`NCGU0 z_Y|ZY4S6YU3|{QG+zzvnM#e( zy3(QCt|&F&>Uv5RNNPZ1anSmi33IRIRrs^h8;`WpL_|6nLDJb~7M(6QB+cRCaBax9 z6~mxFXI$(Zw%};U=eJi4iv1SO@3LDY`S<$@MeeJ+O(rwQJ+IdY9busbP%vVIrYQQX zj^Z#*-rFhh{}K4Qu_`aLqezNh0S}8E7%VX8YEBf5@=^?zyU|oNTe{vMcCtG>Ej#@2 zVat~bt~*}{4XkF=2N18U5p~dHHFhMV2U5f11>gc3z+!fG$@)U`^CoBCb)MaL9-s1P zQvrv>yj!N_svp0oyCwSQNnGxFkK(KKllrlE|41^FsM_$eUa(a;%YmN-QJ*AYz!Nf2 zAP2mFWN`#xKe*Xp0|BXdwGj3(CC%Znj<;yu09!bpKTp$^b=2tVTh1|)Un5zqNY;^! z9>7bt^%QW;X1Q`^%!#PPdKup%w)wPm^XAmq5~gpzHmjtJIjvP+{ciqR)Af20WSh{T zNYL2;@umAQ>ocui+-e6CM{1;Rqh6$Ex1~G43U{`7PN%*2S^3FJVQKQ|SVBqs!hAf` zYARV#vaDfJw}ctmU%+C_T4xIn`+q%f4P5T7jexKk6$p*w@2P%mqp8E=)k7m&Pb$Al zNqK11OUKD;IN1AzZBcico0;Fr->qnG!0^l3dNS6tNijZwks&U|JZHUXl_O3+V|`X%G(Cowg`8 zEzqfUmlOnRi?DbKDF>7Xmx!3vKhZfYM4ABeRC{!8RGl(Pi#aC-ZW4_9-z6H8-@hBN zEDMi=lLm4B;ZgFDGmt_sJxzUL(>p{51V}qsQc;CbeShoHx)hi(^j2w8V3J}xe#(vz z>8gJ#4qPC>LBL!t#~QKQuL0S2{~y>gfsoPQ;uuWiH1fR8?B2Zl&mHbw&Hwrt+?qzF zCSW#qxNj%g9YWzKu!0NeGVvgZxsp2NytAQ$8W8HkXB-eNu3fHw1+r~!6gO7o@Y4gr z;p|%!r(6*ZQq|}j7uR1zm8_mnG88Y)lUPD$aJH=PJl-Hs&n+vF@w(uGurmXMIuJ_4 zWa_QOgS-#+YCy`3^d^w3W530tV6KSQn(`Q>Kgf^P*urJTdp|qv6~g#9ERQzOIlc#l zqk+#X8vx!7Y4Rnnu~Qx>12Xr0VD5KfIK`U%!6{Sy_FS|EhOf|tw*^;sum4uCiMh~r zvHh|1UWjGKG@{oi_wooMCqCaFExUkKL7`5=Y@JJ>us&Eu$dR9p9}7s1R`JE78696u zuL#aK6$crGPox$sGB>2BhBZh~&T(;W zeZ5ll#Q^lhc3*t|y{_evVkUD%q0_>r+GDV;g5-I!Vo-m5DD!sn7s~~<%iCS7)RpdB zXwK-A`ohDOxj9)$rVA-H8ov9{tmvfESe8^iKmNLZe(e@-ORL-$6E_ZSe>n{P z!HHfJ|~nf)B!pm?lS<;c562(As@5r(>l1 zTy`A)n1$%p%`j|32p57Uoa;H}Lf&7gUG5}jt-E2@_+{6(b}orm|KZ93sEkA_E%G%o ziOlgzpc8;-S8mANUbb7DMOI8vpOXA+enm+$*fU^$Xz}y6#+Z^<^Y!m{a}IASb#BL1 zfWUffhd-&&K5R%5fYx9xiH8AUam;}cJ-Jo-;MVu{p@{^qN+My$({rcy)6nZUX7h^+ zvi(1%`kzAm?7}PX4-SP(1#UkSSbTTFt|oT_kqf3K`AZ5_hiXT%d_`AL=b()Tx=&0O zQRqi^9w~lJzUMS>Jk=wc*d-}Xa(Z-nB&3X#=WRfcS`yy(ucONdx|WbTi9L5kYV`(| z!kF95_iWm6q`?b(U~}fz*5g6r?BA(cx=s`FMMw9+IF0I`SWd40KU3w=iko}~qkYLT z+N*gIhkk{N!3j~l@U$CE>USn`72AFSF)-?_1wm$y$)jIs3oQxxdr)S*&FH zlEp4Mnlm*40MK!Bb@YMWW28Uo)K$Z#+SjA#C0ZWiT;Jl5m9{@2KpHkN=0n7IpPEpEA1Q3(Jct;>;A#kE*=?*7= zjsYff+^-XXr$_+f=Ff2jPG0~@tM#jzmN3K=#_eae(t#+HXU^0O*j*(`EDvwN^fs3`!{k7{30AwXj zfu6RjH==rceswircj5Te$TwG2`;C~)roNV%JfR%`yp%-O_L-v#X2vX3jS1~LJf}k? zXq8shy6&Bvv$}TYfvmRY{#`;T8>d5iik>}dX>NYH=(@vl#%=!%ecbZZrT)Dke@2sg zxjamc3tIg>1`mv`yD^LCW|Nz|C$8P? zn6|46chqRR!`}Hf=G^aRziKr9qD*PD1WvD^D6LOK9$(2){^&kWk1i>F)eQih#e%Yj zrs~QuL7QLJg!jL*?RCkT1H^FL_O1nhRgNYo+U)|{N_7Bm%!)NTZLj~nY`S@=>a4OK z>dUlx0ts6jOs3F21#WN#z)L`zq!&kh>G z&()yQMl_DNZH4ot#DzBj+@_wbB`(-~v1h$)9%`Sb79F>mxyAXg);+cao0c#&EB&76 z+)SHYghQ?O@`7}qCs3%Bn9|>-tKqMQU{Dp;9L`vqYb3F%&KRB0&a0Stdg%$};_V+; zHD|(ACdN9IY7kVy9T1G!_O5gf`r@aq#}TtkEG9hHu+mW8;$1$^DCxNSxw)4n{CRyk z6NlYKcQrSDJTYMsT5o+k^}3bG#O+kvyrMnh+|K+$yFc;1^L@ULahrKgx`pdZVgAZOGN~>+-9jCFHE~-H`9>hxcvD(Rg?u&o4J) z$y;B2UvAFAF5HCbA2M2f zpZUJX*36#jX+!#ukID@`s(+~1G5jh&yCWs@%Bq-54?%WA+%aj3pX&h%xT;UH}bD_BwbG0aB0IodTrEnwmlo4XRyp5T6|74 znY5JDkXC)L!*;`s_Xpb0TzZXO%~O0+;iRhh*LfMf=?`4E)3`G~BfZeDI)B>Av*<;$r1A2QMl(#zYA*PZGhbnrU1)&G3Q;^+C90eJDfYd5LCdbiZt zYW=()6Wn+r+KcKH%RS#}jAo$|{ZBqQec@<$Za3rIG|ESc=;tO%6WOW(*ATG!j#cS} zn-{9Qt_d<%$2C$n8uzpNqxx%s?3g)9T;=Vt_OZ*yefbpili}6fwxl}nc>z6pzuK+ff;}gG z2taBUIvo3rw#@X2nc7({=+C)&cl&MPfxOHGciZn2+^*YWb@1KK{p}OWC%)WUcyz0~ zKhl8y`tpf2#IxkJk#(9)Q+`;mb*btJ^2Hs6W}%O~^4k5A^P?}%jq(hRT~&5_Q`vc? z;I~?Snk{h~-qt^9U+G0h2Q;2%eBPR&PnoiPNB-oxX~|PIJ~ge6Xwly$xP3LXe&4yA zyz52m8qR%A+v^5o=JN3ea+6;tkLT+=dwx!*ap}4C4xwrQQj3mUC0{H7 zvu{=3U1&@Dh4!BInMUZi|KdF3$tQkohyMDKj~2f_s#{*t-AlQ3rOr>u&+`%I5%|UJ zOF_47{`TCqPY1q)t~|LobZvX3@_prAHRJJxPl_HsGPrL;^GSHT;H}H}${(-vWxNYV z>JW7N{&BG4m9fwkH?GkY zyt||)d3oQde`o8$l7-bPIxk8(&(^g}^1tYxc8at*^o`^Vxi9H~S7q_R;^q5_I3_{?It}MYL#MZ*^7iv+#KxCri9a zR=>Avw|_=`vF(xV^1k|~@9HKR8X9Aw!Af%q2uyoAkLPN(?iX~2A&=U+18B-~y zMG8T*4=5I_6R|+2FsLWSV|89E@c~ER$`J~3A2X0}_$o7Yzu@ZcVwCVW-|2|7=DRX5 zg7+Pnv}RB?FsBBGnha4VQAHp_A`sC8f)L8!bRD^fLH97}^hB8Y^Z0B*xOhGpJz6p{ zaYmwnjtmJ%kt&f`91@46VXa9PI1=hlF=iDGM)p|mE^`3OBj3>=;la)3Q#;An}j9c zt#KF}9?2wH5Rn863oMdBAc9CHi^*c)t*zLW*4P0Eo}RMuZ$di?SnH%K1`0j6xv&K+ zC_FrKNLV({3F8NDN9Bv5nF2Du%Z;c-N9@1~vl{gC*VHC@ksB2H9lv zSEVD}f|Wxu-nYXkAA-U7GV<@Y5gr8czq2w1qYOBFUoRGLB;gDZXwQWvhdk?bFzVN` z(c#Hx=}{2E`(GFXF(d46jsSsRY0ZEpAs)lVBCV|~tdUGhkO3W|1R|4zV_LJA_~8-$ z8zV5Vwfx_Wz{uQX1u^(skWE1kKh$u+e{s-Q0)7}M`YTHZTA&Ol_W?y>3P&UeMKFZI z5FU#mU54l|K6@y6fOjv1M1YXlVh6d)#P}~hD;pH?{>l`U=_QN_@&D|Z|MsGk@01%H zR>h)34DPRAA9BM7=eLKVG>?L^1INLM=`3AN((U=*pMlUZ1|_5<8Q{ZNiKU#I=qUMD z%Wx<B!d z%vi-TF-NMQe_kvZ{NDvd?Bn8qaC4#(utWj@i97$J<8tuJ=7XgOQ9eGeHES9EpSR9mb4v0qAjHwLxu2QCENIAGjW$woVlVY$G zx_v_ze>8mamzghc68WDuMjq)u9~+LSXaq(fkDY zX^woB9^^wGpbv*WDewAODHZyZJ%Z)x;|Ty!bD%GR+6(}H_CxP&0I&`N0B-^TfRq9N z(*%20-*5&1C4`%!JuTw-?=Na~wjlKE>@kJ$P7aArH&xh8J@}+FF1@sJA~iqf7-oON z+@3{MbE@|ym;iu^^h>7n0AL(o2LRBw{OG)^57asI`b!uT5I}rgKkk6b#vhlwIsbX% z!~8XB)|*CamFSnkyOs2{yIs0Jb|RY9W*)U&#Sc@_7#-@ggJEUuTiw*nN7%981)_az28 Q0MN_LX|ZFzL*S-=0?j5J@Bjb+ literal 0 HcmV?d00001 diff --git a/help.txt b/help.txt new file mode 100644 index 0000000..e69de29 diff --git a/items.csv b/items.csv new file mode 100644 index 0000000..49dd25c --- /dev/null +++ b/items.csv @@ -0,0 +1,7451 @@ +#This file belongs to Essentials. +#version: TeamCity +#If you change this file, it will not be automatically updated after the next release. +#item,id,metadata +stone,1,0 +sstone,1,0 +smoothstone,1,0 +rock,1,0 +grass,2,0 +greendirt,2,0 +greenearth,2,0 +greenland,2,0 +dirt,3,0 +earth,3,0 +land,3,0 +grasslessdirt,3,1 +grasslessearth,3,1 +grasslessland,3,1 +podzol,3,2 +cobblestone,4,0 +cstone,4,0 +cobble,4,0 +wood,5,0 +plank,5,0 +woodenplank,5,0 +woodplank,5,0 +wplank,5,0 +plankwooden,5,0 +plankwood,5,0 +plankw,5,0 +oakplank,5,0 +oakwoodenplank,5,0 +oakwoodplank,5,0 +oakwplank,5,0 +oakplankwooden,5,0 +oakplankwood,5,0 +oakplankw,5,0 +oplank,5,0 +owoodenplank,5,0 +owoodplank,5,0 +owplank,5,0 +oplankwooden,5,0 +oplankwood,5,0 +oplankw,5,0 +pineplank,5,1 +pinewoodenplank,5,1 +pinewoodplank,5,1 +pinewplank,5,1 +pineplankwooden,5,1 +pineplankwood,5,1 +pineplankw,5,1 +pplank,5,1 +pwoodenplank,5,1 +pwoodplank,5,1 +pwplank,5,1 +pplankwooden,5,1 +pplankwood,5,1 +pplankw,5,1 +darkplank,5,1 +darkwoodenplank,5,1 +darkwoodplank,5,1 +darkwplank,5,1 +darkplankwooden,5,1 +darkplankwood,5,1 +darkplankw,5,1 +dplank,5,1 +dwoodenplank,5,1 +dwoodplank,5,1 +dwplank,5,1 +dplankwooden,5,1 +dplankwood,5,1 +dplankw,5,1 +spruceplank,5,1 +sprucewoodenplank,5,1 +sprucewoodplank,5,1 +sprucewplank,5,1 +spruceplankwooden,5,1 +spruceplankwood,5,1 +spruceplankw,5,1 +splank,5,1 +swoodenplank,5,1 +swoodplank,5,1 +swplank,5,1 +splankwooden,5,1 +splankwood,5,1 +splankw,5,1 +birchplank,5,2 +birchwoodenplank,5,2 +birchwoodplank,5,2 +birchwplank,5,2 +birchplankwooden,5,2 +birchplankwood,5,2 +birchplankw,5,2 +bplank,5,2 +bwoodenplank,5,2 +bwoodplank,5,2 +bwplank,5,2 +bplankwooden,5,2 +bplankwood,5,2 +bplankw,5,2 +lightplank,5,2 +lightwoodenplank,5,2 +lightwoodplank,5,2 +lightwplank,5,2 +lightplankwooden,5,2 +lightplankwood,5,2 +lightplankw,5,2 +lplank,5,2 +lwoodenplank,5,2 +lwoodplank,5,2 +lwplank,5,2 +lplankwooden,5,2 +lplankwood,5,2 +lplankw,5,2 +whiteplank,5,2 +whitewoodenplank,5,2 +whitewoodplank,5,2 +whitewplank,5,2 +whiteplankwooden,5,2 +whiteplankwood,5,2 +whiteplankw,5,2 +wwoodenplank,5,2 +wwoodplank,5,2 +wwplank,5,2 +wplankwooden,5,2 +wplankwood,5,2 +wplankw,5,2 +jungleplank,5,3 +junglewoodenplank,5,3 +junglewoodplank,5,3 +junglewplank,5,3 +jungleplankwooden,5,3 +jungleplankwood,5,3 +jungleplankw,5,3 +jplank,5,3 +jwoodenplank,5,3 +jwoodplank,5,3 +jwplank,5,3 +jplankwooden,5,3 +jplankwood,5,3 +jplankw,5,3 +forestplank,5,3 +forestwoodenplank,5,3 +forestwoodplank,5,3 +forestwplank,5,3 +forestplankwooden,5,3 +forestplankwood,5,3 +forestplankw,5,3 +fplank,5,3 +fwoodenplank,5,3 +fwoodplank,5,3 +fwplank,5,3 +fplankwooden,5,3 +fplankwood,5,3 +fplankw,5,3 +acaciaplank,5,4 +acaciawoodenplank,5,4 +acaciawoodplank,5,4 +acaciawplank,5,4 +acaciaplankwooden,5,4 +acaciaplankwood,5,4 +acaciaplankw,5,4 +aplank,5,4 +awoodenplank,5,4 +awoodplank,5,4 +awplank,5,4 +aplankwooden,5,4 +aplankwood,5,4 +aplankw,5,4 +darkoakplank,5,5 +darkoakwoodenplank,5,5 +darkoakwoodplank,5,5 +darkoakwplank,5,5 +darkoakplankwooden,5,5 +darkoakplankwood,5,5 +darkoakplankw,5,5 +doakplank,5,5 +doakwoodenplank,5,5 +doakwoodplank,5,5 +doakwplank,5,5 +doakplankwooden,5,5 +doakplankwood,5,5 +doakplankw,5,5 +doplank,5,5 +dowoodenplank,5,5 +dowoodplank,5,5 +dowplank,5,5 +doplankwooden,5,5 +doplankwood,5,5 +doplankw,5,5 +sapling,6,0 +treesapling,6,0 +logsapling,6,0 +trunksapling,6,0 +woodsapling,6,0 +oaktreesapling,6,0 +oaklogsapling,6,0 +oaktrunksapling,6,0 +oakwoodsapling,6,0 +osapling,6,0 +otreesapling,6,0 +ologsapling,6,0 +otrunksapling,6,0 +owoodsapling,6,0 +darksapling,6,1 +darktreesapling,6,1 +darklogsapling,6,1 +darktrunksapling,6,1 +darkwoodsapling,6,1 +sprucesapling,6,1 +sprucetreesapling,6,1 +sprucelogsapling,6,1 +sprucetrunksapling,6,1 +sprucewoodsapling,6,1 +pinesapling,6,1 +pinetreesapling,6,1 +pinelogsapling,6,1 +pinetrunksapling,6,1 +pinewoodsapling,6,1 +dsapling,6,1 +dtreesapling,6,1 +dlogsapling,6,1 +dtrunksapling,6,1 +dwoodsapling,6,1 +ssapling,6,1 +streesapling,6,1 +slogsapling,6,1 +strunksapling,6,1 +swoodsapling,6,1 +psapling,6,1 +ptreesapling,6,1 +plogsapling,6,1 +ptrunksapling,6,1 +pwoodsapling,6,1 +birchsapling,6,2 +birchtreesapling,6,2 +birchlogsapling,6,2 +birchtrunksapling,6,2 +birchwoodsapling,6,2 +lightsapling,6,2 +lighttreesapling,6,2 +lightlogsapling,6,2 +lighttrunksapling,6,2 +lightwoodsapling,6,2 +whitesapling,6,2 +whitetreesapling,6,2 +whitelogsapling,6,2 +whitetrunksapling,6,2 +whitewoodsapling,6,2 +bsapling,6,2 +btreesapling,6,2 +blogsapling,6,2 +btrunksapling,6,2 +bwoodsapling,6,2 +lsapling,6,2 +ltreesapling,6,2 +llogsapling,6,2 +ltrunksapling,6,2 +lwoodsapling,6,2 +wsapling,6,2 +wtreesapling,6,2 +wlogsapling,6,2 +wtrunksapling,6,2 +wwoodsapling,6,2 +junglesapling,6,3 +jungletreesapling,6,3 +junglelogsapling,6,3 +jungletrunksapling,6,3 +junglewoodsapling,6,3 +forestsapling,6,3 +foresttreesapling,6,3 +forestlogsapling,6,3 +foresttrunksapling,6,3 +forestwoodsapling,6,3 +jsapling,6,3 +jtreesapling,6,3 +jlogsapling,6,3 +jtrunksapling,6,3 +jwoodsapling,6,3 +fsapling,6,3 +ftreesapling,6,3 +flogsapling,6,3 +ftrunksapling,6,3 +fwoodsapling,6,3 +acaciasapling,6,4 +acaciatreesapling,6,4 +acacialogsapling,6,4 +acaciatrunksapling,6,4 +acaciawoodsapling,6,4 +asapling,6,4 +atreesapling,6,4 +alogsapling,6,4 +atrunksapling,6,4 +awoodsapling,6,4 +darkoaksapling,6,5 +darkoaktreesapling,6,5 +darkoaklogsapling,6,5 +darkoaktrunksapling,6,5 +darkoakwoodsapling,6,5 +doaksapling,6,5 +doaktreesapling,6,5 +doaklogsapling,6,5 +doaktrunksapling,6,5 +dosapling,6,5 +dowoodsapling,6,5 +dotreesapling,6,5 +dologsapling,6,5 +dotrunksapling,6,5 +bedrock,7,0 +oprock,7,0 +opblock,7,0 +adminblock,7,0 +adminrock,7,0 +adminium,7,0 +water,8,0 +stationarywater,9,0 +stillwater,9,0 +swater,9,0 +lava,10,0 +stationarylava,11,0 +stilllava,11,0 +slava,11,0 +sand,12,0 +redsand,12,1 +rsand,12,1 +gravel,13,0 +goldore,14,0 +oregold,14,0 +gore,14,0 +oreg,14,0 +ogold,14,0 +goldo,14,0 +ironore,15,0 +oreiron,15,0 +irono,15,0 +oiron,15,0 +steelore,15,0 +oresteel,15,0 +steelo,15,0 +osteel,15,0 +iore,15,0 +orei,15,0 +sore,15,0 +ores,15,0 +coalore,16,0 +orecoal,16,0 +coalo,16,0 +ocoal,16,0 +core,16,0 +tree,17,0 +log,17,0 +trunk,17,0 +oak,17,0 +oaktree,17,0 +oaklog,17,0 +oaktrunk,17,0 +oakwood,17,0 +otree,17,0 +olog,17,0 +otrunk,17,0 +owood,17,0 +pine,17,1 +pinetree,17,1 +pinelog,17,1 +pinetrunk,17,1 +pinewood,17,1 +darktree,17,1 +darklog,17,1 +darktrunk,17,1 +darkwood,17,1 +spruce,17,1 +sprucetree,17,1 +sprucelog,17,1 +sprucetrunk,17,1 +sprucewood,17,1 +dtree,17,1 +dlog,17,1 +dtrunk,17,1 +dwood,17,1 +stree,17,1 +slog,17,1 +strunk,17,1 +swood,17,1 +ptree,17,1 +plog,17,1 +ptrunk,17,1 +pwood,17,1 +birch,17,2 +birchtree,17,2 +birchlog,17,2 +birchtrunk,17,2 +birchwood,17,2 +whitetree,17,2 +whitelog,17,2 +whitetrunk,17,2 +whitewood,17,2 +lighttree,17,2 +lightlog,17,2 +lighttrunk,17,2 +lightwood,17,2 +btree,17,2 +blog,17,2 +btrunk,17,2 +bwood,17,2 +wtree,17,2 +wlog,17,2 +wtrunk,17,2 +wwood,17,2 +ltree,17,2 +llog,17,2 +ltrunk,17,2 +lwood,17,2 +jungletree,17,3 +junglelog,17,3 +jungletrunk,17,3 +junglewood,17,3 +jungle,17,3 +forest,17,3 +foresttree,17,3 +forestlog,17,3 +foresttrunk,17,3 +forestwood,17,3 +jtree,17,3 +jlog,17,3 +jtrunk,17,3 +jwood,17,3 +ftree,17,3 +flog,17,3 +ftrunk,17,3 +fwood,17,3 +leaves,18,0 +leaf,18,0 +treeleaves,18,0 +logleaves,18,0 +trunkleaves,18,0 +woodleaves,18,0 +oakleaves,18,0 +oakleaf,18,0 +oleaves,18,0 +oleaf,18,0 +oaktreeleaves,18,0 +oaklogleaves,18,0 +oaktrunkleaves,18,0 +oakwoodleaves,18,0 +otreeleaves,18,0 +ologleaves,18,0 +otrunkleaves,18,0 +owoodleaves,18,0 +treeleaf,18,0 +logleaf,18,0 +trunkleaf,18,0 +woodleaf,18,0 +oaktreeleaf,18,0 +oaklogleaf,18,0 +oaktrunkleaf,18,0 +oakwoodleaf,18,0 +otreeleaf,18,0 +ologleaf,18,0 +otrunkleaf,18,0 +owoodleaf,18,0 +pineleaves,18,1 +pineleaf,18,1 +pleaves,18,1 +pleaf,18,1 +pinetreeleaves,18,1 +pinelogleaves,18,1 +pinetrunkleaves,18,1 +pinewoodleaves,18,1 +ptreeleaves,18,1 +plogleaves,18,1 +ptrunkleaves,18,1 +pwoodleaves,18,1 +spruceleaves,18,1 +spruceleaf,18,1 +sleaves,18,1 +sleaf,18,1 +sprucetreeleaves,18,1 +sprucelogleaves,18,1 +sprucetrunkleaves,18,1 +sprucewoodleaves,18,1 +streeleaves,18,1 +slogleaves,18,1 +strunkleaves,18,1 +swoodleaves,18,1 +darkleaves,18,1 +darkleaf,18,1 +dleaves,18,1 +dleaf,18,1 +darktreeleaves,18,1 +darklogleaves,18,1 +darktrunkleaves,18,1 +darkwoodleaves,18,1 +dtreeleaves,18,1 +dlogleaves,18,1 +dtrunkleaves,18,1 +dwoodleaves,18,1 +sprucetreeleaf,18,1 +sprucelogleaf,18,1 +sprucetrunkleaf,18,1 +sprucewoodleaf,18,1 +streeleaf,18,1 +slogleaf,18,1 +strunkleaf,18,1 +swoodleaf,18,1 +pinetreeleaf,18,1 +pinelogleaf,18,1 +pinetrunkleaf,18,1 +pinewoodleaf,18,1 +ptreeleaf,18,1 +plogleaf,18,1 +ptrunkleaf,18,1 +pwoodleaf,18,1 +darktreeleaf,18,1 +darklogleaf,18,1 +darktrunkleaf,18,1 +darkwoodleaf,18,1 +dtreeleaf,18,1 +dlogleaf,18,1 +dtrunkleaf,18,1 +dwoodleaf,18,1 +birchleaves,18,2 +birchleaf,18,2 +bleaves,18,2 +bleaf,18,2 +birchtreeleaves,18,2 +birchlogleaves,18,2 +birchtrunkleaves,18,2 +birchwoodleaves,18,2 +btreeleaves,18,2 +blogleaves,18,2 +btrunkleaves,18,2 +bwoodleaves,18,2 +lightleaves,18,2 +lightleaf,18,2 +lleaves,18,2 +lleaf,18,2 +lighttreeleaves,18,2 +lightlogleaves,18,2 +lighttrunkleaves,18,2 +lightwoodleaves,18,2 +ltreeleaves,18,2 +llogleaves,18,2 +ltrunkleaves,18,2 +lwoodleaves,18,2 +whiteleaves,18,2 +whiteleaf,18,2 +wleaves,18,2 +wleaf,18,2 +whitetreeleaves,18,2 +whitelogleaves,18,2 +whitetrunkleaves,18,2 +whitewoodleaves,18,2 +wtreeleaves,18,2 +wlogleaves,18,2 +wtrunkleaves,18,2 +wwoodleaves,18,2 +birchtreeleaf,18,2 +birchlogleaf,18,2 +birchtrunkleaf,18,2 +birchwoodleaf,18,2 +btreeleaf,18,2 +blogleaf,18,2 +btrunkleaf,18,2 +bwoodleaf,18,2 +lighttreeleaf,18,2 +lightlogleaf,18,2 +lighttrunkleaf,18,2 +lightwoodleaf,18,2 +ltreeleaf,18,2 +llogleaf,18,2 +ltrunkleaf,18,2 +lwoodleaf,18,2 +whitetreeleaf,18,2 +whitelogleaf,18,2 +whitetrunkleaf,18,2 +whitewoodleaf,18,2 +wtreeleaf,18,2 +wlogleaf,18,2 +wtrunkleaf,18,2 +wwoodleaf,18,2 +jungleleaves,18,3 +jungleleaf,18,3 +jleaves,18,3 +jleaf,18,3 +jungletreeleaves,18,3 +junglelogleaves,18,3 +jungletrunkleaves,18,3 +junglewoodleaves,18,3 +jtreeleaves,18,3 +jlogleaves,18,3 +jtrunkleaves,18,3 +jwoodleaves,18,3 +forestleaves,18,3 +forestleaf,18,3 +fleaves,18,3 +fleaf,18,3 +foresttreeleaves,18,3 +forestlogleaves,18,3 +foresttrunkleaves,18,3 +forestwoodleaves,18,3 +ftreeleaves,18,3 +flogleaves,18,3 +ftrunkleaves,18,3 +fwoodleaves,18,3 +jungletreeleaf,18,3 +junglelogleaf,18,3 +jungletrunkleaf,18,3 +junglewoodleaf,18,3 +jtreeleaf,18,3 +jlogleaf,18,3 +jtrunkleaf,18,3 +jwoodleaf,18,3 +foresttreeleaf,18,3 +forestlogleaf,18,3 +foresttrunkleaf,18,3 +forestwoodleaf,18,3 +ftreeleaf,18,3 +flogleaf,18,3 +ftrunkleaf,18,3 +fwoodleaf,18,3 +sponge,19,0 +glass,20,0 +blockglass,20,0 +glassblock,20,0 +lapislazuliore,21,0 +lapislazulio,21,0 +orelapislazuli,21,0 +olapislazuli,21,0 +lapisore,21,0 +lapiso,21,0 +orelapis,21,0 +olapis,21,0 +lore,21,0 +orel,21,0 +lapislazuliblock,22,0 +blocklapislazuli,22,0 +lapisblock,22,0 +blocklapis,22,0 +lblock,22,0 +blockl,22,0 +dispenser,23,0 +dispense,23,0 +sandstone,24,0 +sastone,24,0 +creepersandstone,24,1 +creepersastone,24,1 +creepsandstone,24,1 +creepsastone,24,1 +csandstone,24,1 +csastone,24,1 +hieroglyphicsandstone,24,1 +hieroglyphicsastone,24,1 +hieroglyphsandstone,24,1 +hieroglyphsastone,24,1 +hsandstone,24,1 +hsastone,24,1 +pyramidsandstone,24,1 +pyramidsastone,24,1 +psandstone,24,1 +psastone,24,1 +chiseledsandstone,24,1 +chiseledsastone,24,1 +chiselsandstone,24,1 +chiselsastone,24,1 +smoothsandstone,24,2 +smoothsastone,24,2 +ssandstone,24,2 +smsastone,24,2 +ssastone,24,2 +noteblock,25,0 +musicblock,25,0 +nblock,25,0 +mblock,25,0 +poweredtrack,27,0 +poweredrails,27,0 +poweredrail,27,0 +boostertrack,27,0 +boosterrails,27,0 +boosterrail,27,0 +powertrack,27,0 +powerrails,27,0 +powerrail,27,0 +boosttrack,27,0 +boostrails,27,0 +boostrail,27,0 +ptrack,27,0 +prails,27,0 +prail,27,0 +btrack,27,0 +brails,27,0 +brail,27,0 +detectortrack,28,0 +detectorrails,28,0 +detectorrail,28,0 +detectingtrack,28,0 +detectingrails,28,0 +detectingrail,28,0 +detecttrack,28,0 +detectrails,28,0 +detectrail,28,0 +dtrack,28,0 +drails,28,0 +drail,28,0 +stickypistonbase,29,0 +stickypiston,29,0 +stickpistonbase,29,0 +stickpiston,29,0 +stickyp,29,0 +spistonbase,29,0 +spiston,29,0 +pistonstickybase,29,0 +pistonsticky,29,0 +pistonstickbase,29,0 +pistonstick,29,0 +pistonsbase,29,0 +pistons,29,0 +psticky,29,0 +pstick,29,0 +spiderweb,30,0 +cobweb,30,0 +sweb,30,0 +cweb,30,0 +web,30,0 +longgrass,31,1 +tallgrass,31,1 +wildgrass,31,1 +grasslong,31,1 +grasstall,31,1 +grasswild,31,1 +lgrass,31,1 +tgrass,31,1 +wgrass,31,1 +fern,31,2 +bush,31,2 +deadshrub,32,0 +dshrub,32,0 +deadbush,32,0 +dbush,32,0 +deadsapling,32,0 +piston,33,0 +pistonbase,33,0 +pistonblock,33,0 +whitewool,35,0 +whitecloth,35,0 +whitecotton,35,0 +wcloth,35,0 +wwool,35,0 +wcotton,35,0 +cloth,35,0 +wool,35,0 +cotton,35,0 +orangewool,35,1 +orangecloth,35,1 +orangecotton,35,1 +ocloth,35,1 +owool,35,1 +ocotton,35,1 +magentawool,35,2 +magentacloth,35,2 +magentacotton,35,2 +mcloth,35,2 +mwool,35,2 +mcotton,35,2 +lightbluewool,35,3 +lightbluecloth,35,3 +lightbluecotton,35,3 +lbluecloth,35,3 +lbluewool,35,3 +lbluecotton,35,3 +lightblucloth,35,3 +lightbluwool,35,3 +lightblucotton,35,3 +lblucloth,35,3 +lbluwool,35,3 +lblucotton,35,3 +lbcloth,35,3 +lbwool,35,3 +lbcotton,35,3 +yellowwool,35,4 +yellowcloth,35,4 +yellowcotton,35,4 +ycloth,35,4 +ywool,35,4 +ycotton,35,4 +lightgreenwool,35,5 +lightgreencloth,35,5 +lightgreencotton,35,5 +lgreencloth,35,5 +lgreenwool,35,5 +lgreencotton,35,5 +lightgrecloth,35,5 +lightgrewool,35,5 +lightgrecotton,35,5 +lgrecloth,35,5 +lgrewool,35,5 +lgrecotton,35,5 +limecloth,35,5 +limewool,35,5 +limecotton,35,5 +lcloth,35,5 +lwool,35,5 +lcotton,35,5 +pinkwool,35,6 +pinkcloth,35,6 +pinkcotton,35,6 +picloth,35,6 +piwool,35,6 +picotton,35,6 +darkgraywool,35,7 +darkgraycloth,35,7 +darkgraycotton,35,7 +darkgreywool,35,7 +darkgreycloth,35,7 +darkgreycotton,35,7 +dgraycloth,35,7 +dgraywool,35,7 +dgraycotton,35,7 +dgreycloth,35,7 +dgreywool,35,7 +dgreycotton,35,7 +darkgracloth,35,7 +darkgrawool,35,7 +darkgracotton,35,7 +dgracloth,35,7 +dgrawool,35,7 +dgracotton,35,7 +graycloth,35,7 +graywool,35,7 +graycotton,35,7 +greycloth,35,7 +greywool,35,7 +greycotton,35,7 +gracloth,35,7 +grawool,35,7 +gracotton,35,7 +lightgraywool,35,8 +lightgraycloth,35,8 +lightgraycotton,35,8 +lgraycloth,35,8 +lgraywool,35,8 +lgraycotton,35,8 +lightgreywool,35,8 +lightgreycloth,35,8 +lightgreycotton,35,8 +lgreycloth,35,8 +lgreywool,35,8 +lgreycotton,35,8 +lightgracloth,35,8 +lightgrawool,35,8 +lightgracotton,35,8 +lgracloth,35,8 +lgrawool,35,8 +lgracotton,35,8 +silvercloth,35,8 +silverwool,35,8 +silvercotton,35,8 +sicloth,35,8 +siawool,35,8 +siacotton,35,8 +cyanwool,35,9 +cyancloth,35,9 +cyancotton,35,9 +ccloth,35,9 +cwool,35,9 +ccotton,35,9 +purplewool,35,10 +purplecloth,35,10 +purplecotton,35,10 +pucloth,35,10 +puwool,35,10 +pucotton,35,10 +bluewool,35,11 +bluecloth,35,11 +bluecotton,35,11 +blucloth,35,11 +bluwool,35,11 +blucotton,35,11 +brownwool,35,12 +browncloth,35,12 +browncotton,35,12 +brocloth,35,12 +browool,35,12 +brocotton,35,12 +darkgreenwool,35,13 +darkgreencloth,35,13 +darkgreencotton,35,13 +dgreencloth,35,13 +dgreenwool,35,13 +dgreencotton,35,13 +greencloth,35,13 +greenwool,35,13 +greencotton,35,13 +darkgrecloth,35,13 +darkgrewool,35,13 +darkgrecotton,35,13 +dgrecloth,35,13 +dgrewool,35,13 +dgrecotton,35,13 +grecloth,35,13 +grewool,35,13 +grecotton,35,13 +redwool,35,14 +redcloth,35,14 +redcotton,35,14 +rcloth,35,14 +rwool,35,14 +rcotton,35,14 +blackwool,35,15 +blackcloth,35,15 +blackcotton,35,15 +blacloth,35,15 +blawool,35,15 +blacotton,35,15 +dandelion,37,0 +yellowdandelion,37,0 +ydandelion,37,0 +yellowflower,37,0 +yflower,37,0 +flower,37,0 +rose,38,0 +redrose,38,0 +rrose,38,0 +redflower,38,0 +rflower,38,0 +poppy,38,0 +redpoppy,38,0 +blueorchid,38,1 +cyanorchid,38,1 +lightblueorchid,38,1 +lblueorchid,38,1 +orchid,38,1 +allium,38,2 +magentaallium,38,2 +azurebluet,38,3 +whiteazurebluet,38,3 +abluet,38,3 +azureb,38,3 +houstonia,38,3 +redtulip,38,4 +tulipred,38,4 +rtulip,38,4 +tulipr,38,4 +orangetulip,38,5 +tuliporange,38,5 +otulip,38,5 +tulipo,38,5 +whitetulip,38,6 +tulipwhite,38,6 +wtulip,38,6 +tulipw,38,6 +pinktulip,38,7 +tulippink,38,7 +ptulip,38,7 +tulipp,38,7 +oxeye,38,8 +daisy,38,8 +oxeyedaisy,38,8 +daisyoxeye,38,8 +moondaisy,38,8 +daisymoon,38,8 +lightgrayoxeye,38,8 +lgrayoxeye,38,8 +lightgreyoxeye,38,8 +lgreyoxeye,38,8 +brownmushroom,39,0 +brownshroom,39,0 +brownmush,39,0 +bmushroom,39,0 +bshroom,39,0 +bmush,39,0 +redmushroom,40,0 +redshroom,40,0 +redmush,40,0 +rmushroom,40,0 +rshroom,40,0 +rmush,40,0 +goldblock,41,0 +blockgold,41,0 +gblock,41,0 +blockg,41,0 +ironblock,42,0 +steelblock,42,0 +blockiron,42,0 +blocksteel,42,0 +iblock,42,0 +stblock,42,0 +blocki,42,0 +blockst,42,0 +stonedoublestep,43,0 +stonedstep,43,0 +sdoublestep,43,0 +sdstep,43,0 +doublestonestep,43,0 +dstonestep,43,0 +doublesstep,43,0 +doublestep,43,0 +dstep,43,0 +stonedoubleslab,43,0 +stonedslab,43,0 +sdoubleslab,43,0 +sdslab,43,0 +doublestoneslab,43,0 +dstoneslab,43,0 +doublesslab,43,0 +doubleslab,43,0 +dslab,43,0 +stonedoublehalfblock,43,0 +stonedhalfblock,43,0 +sdoublehalfblock,43,0 +sdhalfblock,43,0 +doublestonehalfblock,43,0 +dstonehalfblock,43,0 +doubleshalfblock,43,0 +doublehalfblock,43,0 +dhalfblock,43,0 +sandstonedoublestep,43,1 +sandstonedstep,43,1 +sstonedoublestep,43,1 +sstonedstep,43,1 +ssdoublestep,43,1 +ssdstep,43,1 +doublesandstonestep,43,1 +dsandstonestep,43,1 +doublesstonestep,43,1 +dsstonestep,43,1 +doublessstep,43,1 +dsstep,43,1 +sandstonedoubleslab,43,1 +sandstonedslab,43,1 +sstonedoubleslab,43,1 +sstonedslab,43,1 +ssdoubleslab,43,1 +ssdslab,43,1 +doublesandstoneslab,43,1 +dsandstoneslab,43,1 +doublesstoneslab,43,1 +dsstoneslab,43,1 +doublessslab,43,1 +dsslab,43,1 +sandstonedoublehalfblock,43,1 +sandstonedhalfblock,43,1 +sstonedoublehalfblock,43,1 +sstonedhalfblock,43,1 +ssdoublehalfblock,43,1 +ssdhalfblock,43,1 +doublesandstonehalfblock,43,1 +dsandstonehalfblock,43,1 +doublesstonehalfblock,43,1 +dsstonehalfblock,43,1 +doublesshalfblock,43,1 +dsshalfblock,43,1 +plankstonedoublestep,43,2 +woodenstonedoublestep,43,2 +woodenstonedstep,43,2 +woodstonedoublestep,43,2 +woodstonedstep,43,2 +wstonedoublestep,43,2 +wstonedstep,43,2 +doublewoodenstonestep,43,2 +dwoodenstonestep,43,2 +doublewoodstonestep,43,2 +dwoodstonestep,43,2 +doublewstonestep,43,2 +dwstonestep,43,2 +woodenstonedoubleslab,43,2 +woodenstonedslab,43,2 +woodstonedoubleslab,43,2 +woodstonedslab,43,2 +wstonedoubleslab,43,2 +wstonedslab,43,2 +doublewoodenstoneslab,43,2 +dwoodenstoneslab,43,2 +doublewoodstoneslab,43,2 +dwoodstoneslab,43,2 +doublewstoneslab,43,2 +dwstoneslab,43,2 +woodenstonedoublehalfblock,43,2 +woodenstonedhalfblock,43,2 +woodstonedoublehalfblock,43,2 +woodstonedhalfblock,43,2 +wstonedoublehalfblock,43,2 +wstonedhalfblock,43,2 +doublewoodenstonehalfblock,43,2 +dwoodenstonehalfblock,43,2 +doublewoodstonehalfblock,43,2 +dwoodstonehalfblock,43,2 +doublewstonehalfblock,43,2 +dwstonehalfblock,43,2 +cobblestonedoublestep,43,3 +cobblestonedstep,43,3 +cobbledoublestep,43,3 +cobbledstep,43,3 +cstonedoublestep,43,3 +cstonedstep,43,3 +csdoublestep,43,3 +csdstep,43,3 +doublecobblestonestep,43,3 +dcobblestonestep,43,3 +doublecobblestep,43,3 +dcobblestep,43,3 +doublecstonestep,43,3 +dcstonestep,43,3 +doublecsstep,43,3 +dcsstep,43,3 +cobblestonedoubleslab,43,3 +cobblestonedslab,43,3 +cobbledoubleslab,43,3 +cobbledslab,43,3 +cstonedoubleslab,43,3 +cstonedslab,43,3 +csdoubleslab,43,3 +csdslab,43,3 +doublecobblestoneslab,43,3 +dcobblestoneslab,43,3 +doublecobbleslab,43,3 +dcobbleslab,43,3 +doublecstoneslab,43,3 +dcstoneslab,43,3 +doublecsslab,43,3 +dcsslab,43,3 +cobblestonedoublehalfblock,43,3 +cobblestonedhalfblock,43,3 +cobbledoublehalfblock,43,3 +cobbledhalfblock,43,3 +cstonedoublehalfblock,43,3 +cstonedhalfblock,43,3 +csdoublehalfblock,43,3 +csdhalfblock,43,3 +doublecobblestonehalfblock,43,3 +dcobblestonehalfblock,43,3 +doublecobblehalfblock,43,3 +dcobblehalfblock,43,3 +doublecstonehalfblock,43,3 +dcstonehalfblock,43,3 +doublecshalfblock,43,3 +dcshalfblock,43,3 +brickdoublestep,43,4 +brickdstep,43,4 +bdoublestep,43,4 +bdstep,43,4 +brickdoubleslab,43,4 +brickdslab,43,4 +bdoubleslab,43,4 +bdslab,43,4 +doublebrickstep,43,4 +dbrickstep,43,4 +doublebstep,43,4 +dbstep,43,4 +doublebrickslab,43,4 +dbrickslab,43,4 +doublebslab,43,4 +dbslab,43,4 +brickdoublehalfblock,43,4 +brickdhalfblock,43,4 +bdoublehalfblock,43,4 +bdhalfblock,43,4 +doublebrickhalfblock,43,4 +dbrickhalfblock,43,4 +doublebhalfblock,43,4 +dbhalfblock,43,4 +stonebrickdoublestep,43,5 +stonebrickdstep,43,5 +stonebdoublestep,43,5 +stonebdstep,43,5 +sbrickdoublestep,43,5 +sbrickdstep,43,5 +sbdoublestep,43,5 +sbdstep,43,5 +stonebrickdoubleslab,43,5 +stonebrickdslab,43,5 +stonebdoubleslab,43,5 +stonebdslab,43,5 +sbrickdoubleslab,43,5 +sbrickdslab,43,5 +sbdoubleslab,43,5 +sbdslab,43,5 +doublestonebrickstep,43,5 +dstonebrickstep,43,5 +doublestonebstep,43,5 +dstonebstep,43,5 +doublesbrickstep,43,5 +dsbrickstep,43,5 +doublesbstep,43,5 +dsbstep,43,5 +doublestonebrickslab,43,5 +dstonebrickslab,43,5 +doublestonebslab,43,5 +dstonebslab,43,5 +doublesbrickslab,43,5 +dsbrickdslab,43,5 +doublesbslab,43,5 +dsbslab,43,5 +stonebrickdoublehalfblock,43,5 +stonebrickdhalfblock,43,5 +stonebdoublehalfblock,43,5 +stonebdhalfblock,43,5 +sbrickdoublehalfblock,43,5 +sbrickdhalfblock,43,5 +sbdoublehalfblock,43,5 +sbdhalfblock,43,5 +doublestonebrickhalfblock,43,5 +dstonebrickhalfblock,43,5 +doublestonebhalfblock,43,5 +dstonebhalfblock,43,5 +doublesbrickhalfblock,43,5 +dsbrickhalfblock,43,5 +doublesbhalfblock,43,5 +dsbhalfblock,43,5 +netherbrickdoubleslab,43,6 +hellbrickdoubleslab,43,6 +nbrickdoubleslab,43,6 +hbrickdoubleslab,43,6 +netherdoubleslab,43,6 +helldoubleslab,43,6 +nbdoubleslab,43,6 +hbdoubleslab,43,6 +hdoubleslab,43,6 +ndoubleslab,43,6 +netherbrickdoublestep,43,6 +hellbrickdoublestep,43,6 +nbrickdoublestep,43,6 +hbrickdoublestep,43,6 +netherdoublestep,43,6 +helldoublestep,43,6 +nbdoublestep,43,6 +hbdoublestep,43,6 +ndoublestep,43,6 +hdoublestep,43,6 +netherbrickdoublehalfblock,43,6 +hellbrickdoublehalfblock,43,6 +nbrickdoublehalfblock,43,6 +hbrickdoublehalfblock,43,6 +netherdoublehalfblock,43,6 +helldoublehalfblock,43,6 +nbdoublehalfblock,43,6 +hbdoublehalfblock,43,6 +ndoublehalfblock,43,6 +hdoublehalfblock,43,6 +netherbrickdslab,43,6 +hellbrickdslab,43,6 +nbrickdslab,43,6 +hbrickdslab,43,6 +netherdslab,43,6 +helldslab,43,6 +nbdslab,43,6 +hbdslab,43,6 +hdslab,43,6 +ndslab,43,6 +netherbrickdstep,43,6 +hellbrickdstep,43,6 +nbrickdstep,43,6 +hbrickdstep,43,6 +netherdstep,43,6 +helldstep,43,6 +nbdstep,43,6 +hbdstep,43,6 +ndstep,43,6 +hdstep,43,6 +netherbrickdhalfblock,43,6 +hellbrickdhalfblock,43,6 +nbrickdhalfblock,43,6 +hbrickdhalfblock,43,6 +netherdhalfblock,43,6 +helldhalfblock,43,6 +nbdhalfblock,43,6 +hbdhalfblock,43,6 +ndhalfblock,43,6 +hdhalfblock,43,6 +doublenetherbrickslab,43,6 +doublehellbrickslab,43,6 +doublenbrickslab,43,6 +doublehbrickslab,43,6 +doublenetherslab,43,6 +doublehellslab,43,6 +doublenbslab,43,6 +doublehbslab,43,6 +doublehslab,43,6 +doublenslab,43,6 +doublenetherbrickstep,43,6 +doublehellbrickstep,43,6 +doublenbrickstep,43,6 +doublehbrickstep,43,6 +doublenetherstep,43,6 +doublehellstep,43,6 +doublenbstep,43,6 +doublehbstep,43,6 +doublenstep,43,6 +doublehstep,43,6 +doublenetherbrickhalfblock,43,6 +doublehellbrickhalfblock,43,6 +doublenbrickhalfblock,43,6 +doublehbrickhalfblock,43,6 +doublenetherhalfblock,43,6 +doublehellhalfblock,43,6 +doublenbhalfblock,43,6 +doublehbhalfblock,43,6 +doublenhalfblock,43,6 +doublehhalfblock,43,6 +dnetherbrickslab,43,6 +dhellbrickslab,43,6 +dnbrickslab,43,6 +dhbrickslab,43,6 +dnetherslab,43,6 +dhellslab,43,6 +dnbslab,43,6 +dhbslab,43,6 +dhslab,43,6 +dnslab,43,6 +dnetherbrickstep,43,6 +dhellbrickstep,43,6 +dnbrickstep,43,6 +dhbrickstep,43,6 +dnetherstep,43,6 +dhellstep,43,6 +dnbstep,43,6 +dhbstep,43,6 +dnstep,43,6 +dhstep,43,6 +dnetherbrickhalfblock,43,6 +dhellbrickhalfblock,43,6 +dnbrickhalfblock,43,6 +dhbrickhalfblock,43,6 +dnetherhalfblock,43,6 +dhellhalfblock,43,6 +dnbhalfblock,43,6 +dhbhalfblock,43,6 +dnhalfblock,43,6 +dhhalfblock,43,6 +netherquartzdoublestep,43,7 +hellquartzdoublestep,43,7 +deathquartzdoublestep,43,7 +nquartzdoublestep,43,7 +hquartzdoublestep,43,7 +dquartzdoublestep,43,7 +quartzdoublestep,43,7 +nqdoublestep,43,7 +hqdoublestep,43,7 +dqdoublestep,43,7 +qdoublestep,43,7 +netherquartzdoubleslab,43,7 +hellquartzdoubleslab,43,7 +deathquartzdoubleslab,43,7 +nquartzdoubleslab,43,7 +hquartzdoubleslab,43,7 +dquartzdoubleslab,43,7 +quartzdoubleslab,43,7 +nqdoubleslab,43,7 +hqdoubleslab,43,7 +dqdoubleslab,43,7 +qdoubleslab,43,7 +netherquartzdoublehalfblock,43,7 +hellquartzdoublehalfblock,43,7 +deathquartzdoublehalfblock,43,7 +nquartzdoublehalfblock,43,7 +hquartzdoublehalfblock,43,7 +dquartzdoublehalfblock,43,7 +quartzdoublehalfblock,43,7 +nqdoublehalfblock,43,7 +hqdoublehalfblock,43,7 +dqdoublehalfblock,43,7 +qdoublehalfblock,43,7 +netherquartzdslab,43,7 +hellquartzdslab,43,7 +deathquartzdslab,43,7 +nquartzdslab,43,7 +hquartzdslab,43,7 +dquartzdslab,43,7 +quartzdslab,43,7 +nqdslab,43,7 +hqdslab,43,7 +dqdslab,43,7 +qdslab,43,7 +netherquartzdstep,43,7 +hellquartzdstep,43,7 +deathquartzdstep,43,7 +nquartzdstep,43,7 +hquartzdstep,43,7 +dquartzdstep,43,7 +quartzdstep,43,7 +nqdstep,43,7 +hqdstep,43,7 +dqdstep,43,7 +qdstep,43,7 +netherquartzdhalfblock,43,7 +hellquartzdhalfblock,43,7 +deathquartzdhalfblock,43,7 +nquartzdhalfblock,43,7 +hquartzdhalfblock,43,7 +dquartzdhalfblock,43,7 +quartzdhalfblock,43,7 +nqdhalfblock,43,7 +hqdhalfblock,43,7 +dqdhalfblock,43,7 +qdhalfblock,43,7 +doublenetherquartzslab,43,7 +doublehellquartzslab,43,7 +doubledeathquartzslab,43,7 +doublenquartzslab,43,7 +doublehquartzslab,43,7 +doubledquartzslab,43,7 +doublequartzslab,43,7 +doublenqslab,43,7 +doublehqslab,43,7 +doubledqslab,43,7 +doubleqslab,43,7 +doublenetherquartzstep,43,7 +doublehellquartzstep,43,7 +doubledeathquartzstep,43,7 +doublenquartzstep,43,7 +doublehquartzstep,43,7 +doubledquartzstep,43,7 +doublequartzstep,43,7 +doublenqstep,43,7 +doublehqstep,43,7 +doubledqstep,43,7 +doubleqstep,43,7 +doublenetherquartzhalfblock,43,7 +doublehellquartzhalfblock,43,7 +doubledeathquartzhalfblock,43,7 +doublenquartzhalfblock,43,7 +doublehquartzhalfblock,43,7 +doubledquartzhalfblock,43,7 +doublequartzhalfblock,43,7 +doublenqhalfblock,43,7 +doublehqhalfblock,43,7 +doubledqhalfblock,43,7 +doubleqhalfblock,43,7 +dnetherquartzslab,43,7 +dhellquartzslab,43,7 +ddeathquartzslab,43,7 +dnquartzslab,43,7 +dhquartzslab,43,7 +ddquartzslab,43,7 +dnqslab,43,7 +dhqslab,43,7 +ddqslab,43,7 +dnetherquartzstep,43,7 +dhellquartzstep,43,7 +ddeathquartzstep,43,7 +dnquartzstep,43,7 +dhquartzstep,43,7 +ddquartzstep,43,7 +dnqstep,43,7 +dhqstep,43,7 +ddqstep,43,7 +dnetherquartzhalfblock,43,7 +dhellquartzhalfblock,43,7 +ddeathquartzhalfblock,43,7 +dnquartzhalfblock,43,7 +dhquartzhalfblock,43,7 +ddquartzhalfblock,43,7 +dnqhalfblock,43,7 +dhqhalfblock,43,7 +ddqhalfblock,43,7 +smoothstonedoubleslab,43,8 +smoothstonedoublestep,43,8 +smoothstonedoublehalfblock,43,8 +smoothstonedslab,43,8 +smoothstonedstep,43,8 +smoothstonedhalfblock,43,8 +doublesmoothstoneslab,43,8 +doublesmoothstonestep,43,8 +doublesmoothstonehalfblock,43,8 +dsmoothstoneslab,43,8 +dsmoothstonestep,43,8 +dsmoothstonehalfblock,43,8 +smoothsandstonedoubleslab,43,9 +ssandstonedoubleslab,43,9 +ssstonedoubleslab,43,9 +sssdoubleslab,43,9 +smoothsandstonedoublestep,43,9 +ssandstonedoublestep,43,9 +ssstonedoublestep,43,9 +sssdoublestep,43,9 +smoothsandstonedoublehalfblock,43,9 +ssandstonedoublehalfblock,43,9 +ssstonedoublehalfblock,43,9 +sssdoublehalfblock,43,9 +smoothsandstonedslab,43,9 +ssandstonedslab,43,9 +ssstonedslab,43,9 +sssdslab,43,9 +smoothsandstonedstep,43,9 +ssandstonedstep,43,9 +ssstonedstep,43,9 +sssdstep,43,9 +smoothsandstonedhalfblock,43,9 +ssandstonedhalfblock,43,9 +ssstonedhalfblock,43,9 +sssdhalfblock,43,9 +doublesmoothsandstoneslab,43,9 +doublessandstoneslab,43,9 +doublessstoneslab,43,9 +doublesssslab,43,9 +doublesmoothsandstonestep,43,9 +doublessandstonestep,43,9 +doublessstonestep,43,9 +doublesssstep,43,9 +doublesmoothsandstonehalfblock,43,9 +doublessandstonehalfblock,43,9 +doublessstonehalfblock,43,9 +doublessshalfblock,43,9 +dsmoothsandstoneslab,43,9 +dssandstoneslab,43,9 +dssstoneslab,43,9 +dsssslab,43,9 +dsmoothsandstonestep,43,9 +dssandstonestep,43,9 +dssstonestep,43,9 +dsssstep,43,9 +dsmoothsandstonehalfblock,43,9 +dssandstonehalfblock,43,9 +dssstonehalfblock,43,9 +dssshalfblock,43,9 +smoothstonestep,44,0 +stonestep,44,0 +sstep,44,0 +step,44,0 +smoothstoneslab,44,0 +stoneslab,44,0 +sslab,44,0 +slab,44,0 +smoothstonehalfblock,44,0 +stonehalfblock,44,0 +shalfblock,44,0 +halfblock,44,0 +sandstonestep,44,1 +sstonestep,44,1 +ssstep,44,1 +sandstoneslab,44,1 +sstoneslab,44,1 +ssslab,44,1 +sandstonehalfblock,44,1 +sstonehalfblock,44,1 +sshalfblock,44,1 +woodenstonestep,44,2 +woodstonestep,44,2 +wstonestep,44,2 +woodenstoneslab,44,2 +woodstoneslab,44,2 +wstoneslab,44,2 +woodenstonehalfblock,44,2 +woodstonehalfblock,44,2 +wstonehalfblock,44,2 +cobblestonestep,44,3 +cobblestep,44,3 +cstonestep,44,3 +csstep,44,3 +cobblestoneslab,44,3 +cobbleslab,44,3 +cstoneslab,44,3 +csslab,44,3 +cobblestonehalfblock,44,3 +cobblehalfblock,44,3 +cstonehalfblock,44,3 +cshalfblock,44,3 +brickstep,44,4 +bstep,44,4 +brickslab,44,4 +bslab,44,4 +brickhalfblock,44,4 +bhalfblock,44,4 +stonebrickstep,44,5 +stonebstep,44,5 +sbrickstep,44,5 +sbstep,44,5 +stonebrickslab,44,5 +stonebslab,44,5 +sbrickslab,44,5 +sbslab,44,5 +stonebrickhalfblock,44,5 +stonebhalfblock,44,5 +sbrickhalfblock,44,5 +sbhalfblock,44,5 +netherbrickslab,44,6 +hellbrickslab,44,6 +nbrickslab,44,6 +hbrickslab,44,6 +netherslab,44,6 +hellslab,44,6 +nbslab,44,6 +hbslab,44,6 +hslab,44,6 +nslab,44,6 +netherbrickstep,44,6 +hellbrickstep,44,6 +nbrickstep,44,6 +hbrickstep,44,6 +netherstep,44,6 +hellstep,44,6 +nbstep,44,6 +hbstep,44,6 +nstep,44,6 +hstep,44,6 +netherbrickhalfblock,44,6 +hellbrickhalfblock,44,6 +nbrickhalfblock,44,6 +hbrickhalfblock,44,6 +netherhalfblock,44,6 +hellhalfblock,44,6 +nbhalfblock,44,6 +hbhalfblock,44,6 +nhalfblock,44,6 +hhalfblock,44,6 +netherquartzstep,44,7 +hellquartzstep,44,7 +deathquartzstep,44,7 +nquartzstep,44,7 +hquartzstep,44,7 +dquartzstep,44,7 +quartzstep,44,7 +nqstep,44,7 +hqstep,44,7 +dqstep,44,7 +qstep,44,7 +netherquartzslab,44,7 +hellquartzslab,44,7 +deathquartzslab,44,7 +nquartzslab,44,7 +hquartzslab,44,7 +dquartzslab,44,7 +quartzslab,44,7 +nqslab,44,7 +hqslab,44,7 +dqslab,44,7 +qslab,44,7 +netherquartzhalfblock,44,7 +hellquartzhalfblock,44,7 +deathquartzhalfblock,44,7 +nquartzhalfblock,44,7 +hquartzhalfblock,44,7 +dquartzhalfblock,44,7 +quartzhalfblock,44,7 +nqhalfblock,44,7 +hqhalfblock,44,7 +dqhalfblock,44,7 +qhalfblock,44,7 +brickblock,45,0 +blockbrick,45,0 +bblock,45,0 +blockb,45,0 +tnt,46,0 +tntblock,46,0 +blocktnt,46,0 +bombblock,46,0 +blockbomb,46,0 +dynamiteblock,46,0 +blockdynamite,46,0 +bomb,46,0 +dynamite,46,0 +bookcase,47,0 +casebook,47,0 +bookshelf,47,0 +shelfbook,47,0 +bookblock,47,0 +blockbook,47,0 +mossycobblestone,48,0 +mosscobblestone,48,0 +mcobblestone,48,0 +mossycobble,48,0 +mosscobble,48,0 +mcobble,48,0 +mossstone,48,0 +mossystone,48,0 +mstone,48,0 +obsidian,49,0 +obsi,49,0 +obby,49,0 +torch,50,0 +burningstick,50,0 +burnstick,50,0 +fire,51,0 +flame,51,0 +flames,51,0 +mobspawner,52,0 +mobcage,52,0 +monsterspawner,52,0 +monstercage,52,0 +mspawner,52,0 +mcage,52,0 +spawner,52,0 +cage,52,0 +woodenstairs,53,0 +woodstairs,53,0 +wstairs,53,0 +woodenstair,53,0 +woodstair,53,0 +wstair,53,0 +chest,54,0 +container,54,0 +diamondore,56,0 +crystalore,56,0 +orediamond,56,0 +orecrystal,56,0 +dore,56,0 +ored,56,0 +diamondblock,57,0 +blockdiamond,57,0 +crystalblock,57,0 +blockcrystal,57,0 +dblock,57,0 +blockd,57,0 +workbench,58,0 +craftingbench,58,0 +crafterbench,58,0 +craftbench,58,0 +worktable,58,0 +craftingtable,58,0 +craftertable,58,0 +crafttable,58,0 +wbench,58,0 +cbench,58,0 +soil,60,0 +furnace,61,0 +litfurnace,62,0 +lfurnace,62,0 +burningfurnace,62,0 +burnfurnace,62,0 +bfurnace,62,0 +ladder,65,0 +minecarttrack,66,0 +minecartrails,66,0 +minecartrail,66,0 +mcarttrack,66,0 +mcartrails,66,0 +mcartrail,66,0 +mctrack,66,0 +mcrails,66,0 +mcrail,66,0 +track,66,0 +rails,66,0 +rail,66,0 +cobblestonestairs,67,0 +cstonestairs,67,0 +stonestairs,67,0 +cobblestairs,67,0 +csstairs,67,0 +sstairs,67,0 +cstairs,67,0 +cobblestonestair,67,0 +cstonestair,67,0 +stonestair,67,0 +cobblestair,67,0 +csstair,67,0 +sstair,67,0 +cstair,67,0 +lever,69,0 +stonepressureplate,70,0 +stonepressplate,70,0 +stonepplate,70,0 +stoneplate,70,0 +spressureplate,70,0 +spressplate,70,0 +spplate,70,0 +splate,70,0 +smoothstonepressureplate,70,0 +smoothstonepressplate,70,0 +smoothstonepplate,70,0 +smoothstoneplate,70,0 +sstonepressureplate,70,0 +sstonepressplate,70,0 +sstonepplate,70,0 +sstoneplate,70,0 +woodenpressureplate,72,0 +woodenpressplate,72,0 +woodenpplate,72,0 +woodenplate,72,0 +woodpressureplate,72,0 +woodpressplate,72,0 +woodpplate,72,0 +woodplate,72,0 +wpressureplate,72,0 +wpressplate,72,0 +wpplate,72,0 +wplate,72,0 +redstoneore,73,0 +redsore,73,0 +redore,73,0 +rstoneore,73,0 +rsore,73,0 +rore,73,0 +oreredstone,73,0 +orereds,73,0 +orered,73,0 +orerstone,73,0 +orers,73,0 +orer,73,0 +redstonetorch,76,0 +rstonetorch,76,0 +redstorch,76,0 +redtorch,76,0 +rstorch,76,0 +stonebutton,77,0 +smoothstonebutton,77,0 +sstonebutton,77,0 +sbutton,77,0 +button,77,0 +snowcover,78,0 +snowcovering,78,0 +scover,78,0 +ice,79,0 +frozenwater,79,0 +waterfrozen,79,0 +freezewater,79,0 +waterfreeze,79,0 +snowblock,80,0 +blocksnow,80,0 +sblock,80,0 +blocks,80,0 +cactus,81,0 +cactuses,81,0 +cacti,81,0 +clayblock,82,0 +blockclay,82,0 +cblock,82,0 +blockc,82,0 +jukebox,84,0 +jbox,84,0 +woodenfence,85,0 +fence,85,0 +woodfence,85,0 +wfence,85,0 +fencewooden,85,0 +fencewood,85,0 +fencew,85,0 +pumpkin,86,0 +netherrack,87,0 +netherrock,87,0 +netherstone,87,0 +hellrack,87,0 +hellrock,87,0 +hellstone,87,0 +deathrack,87,0 +deathrock,87,0 +deathstone,87,0 +nrack,87,0 +nrock,87,0 +nstone,87,0 +hrack,87,0 +hrock,87,0 +hstone,87,0 +drack,87,0 +drock,87,0 +dstone,87,0 +soulsand,88,0 +slowsand,88,0 +slowmud,88,0 +ssand,88,0 +smud,88,0 +mud,88,0 +glowstone,89,0 +glowingstoneblock,89,0 +lightstoneblock,89,0 +glowstoneblock,89,0 +blockglowingstone,89,0 +blocklightstone,89,0 +blockglowstone,89,0 +glowingstone,89,0 +lightstone,89,0 +glowingblock,89,0 +lightblock,89,0 +glowblock,89,0 +lstone,89,0 +gstone,89,0 +portal,90,0 +jackolantern,91,0 +pumpkinlantern,91,0 +glowingpumpkin,91,0 +lightpumpkin,91,0 +jpumpkin,91,0 +plantren,91,0 +glowpumpkin,91,0 +gpumpkin,91,0 +lpumpkin,91,0 +lockedchest,95,0 +lockchest,95,0 +jokechest,95,0 +whiteglass,95,0 +whitesglass,95,0 +whitestainedglass,95,0 +wglass,95,0 +wsglass,95,0 +wstainedglass,95,0 +sglass,95,0 +stainedglass,95,0 +orangeglass,95,1 +orangesglass,95,1 +orangestainedglass,95,1 +oglass,95,1 +osglass,95,1 +ostainedglass,95,1 +magentaglass,95,2 +magentasglass,95,2 +magentastainedglass,95,2 +mglass,95,2 +msglass,95,2 +mstainedglass,95,2 +lightblueglass,95,3 +lightbluesglass,95,3 +lightbluestainedglass,95,3 +lblueglass,95,3 +lbluesglass,95,3 +lbluestainedglass,95,3 +lightbluglass,95,3 +lightblusglass,95,3 +lightblustainedglass,95,3 +lbluglass,95,3 +lblusglass,95,3 +lblustainedglass,95,3 +lbglass,95,3 +lbsglass,95,3 +lbstainedglass,95,3 +yellowglass,95,4 +yellowsglass,95,4 +yellowstainedglass,95,4 +yglass,95,4 +ysglass,95,4 +ystainedglass,95,4 +lightgreenglass,95,5 +lightgreensglass,95,5 +lightgreenstainedglass,95,5 +lgreenglass,95,5 +lgreensglass,95,5 +lgreenstainedglass,95,5 +lightgreglass,95,5 +lightgresglass,95,5 +lightgrestainedglass,95,5 +lgreglass,95,5 +lgresglass,95,5 +lgrestainedglass,95,5 +limeglass,95,5 +limesglass,95,5 +limestainedglass,95,5 +lglass,95,5 +lsglass,95,5 +lstainedglass,95,5 +pinkglass,95,6 +pinksglass,95,6 +pinkstainedglass,95,6 +piglass,95,6 +pisglass,95,6 +pistainedglass,95,6 +darkgrayglass,95,7 +darkgraysglass,95,7 +darkgraystainedglass,95,7 +dgrayglass,95,7 +dgraysglass,95,7 +dgraystainedglass,95,7 +darkgreyglass,95,7 +darkgreysglass,95,7 +darkgreystainedglass,95,7 +dgreyglass,95,7 +dgreysglass,95,7 +dgreystainedglass,95,7 +darkgraglass,95,7 +darkgrasglass,95,7 +darkgrastainedglass,95,7 +dgraglass,95,7 +dgrasglass,95,7 +dgrastainedglass,95,7 +grayglass,95,7 +graysglass,95,7 +graystainedglass,95,7 +greyglass,95,7 +greysglass,95,7 +greystainedglass,95,7 +graglass,95,7 +grasglass,95,7 +grastainedglass,95,7 +lightgrayglass,95,8 +lightgraysglass,95,8 +lightgraystainedglass,95,8 +lgrayglass,95,8 +lgraysglass,95,8 +lgraystainedglass,95,8 +lightgreyglass,95,8 +lightgreysglass,95,8 +lightgreystainedglass,95,8 +lgreyglass,95,8 +lgreysglass,95,8 +lgreystainedglass,95,8 +lightgraglass,95,8 +lightgrasglass,95,8 +lightgrastainedglass,95,8 +lgraglass,95,8 +lgrasglass,95,8 +lgrastainedglass,95,8 +silverglass,95,8 +silversglass,95,8 +silverstainedglass,95,8 +siglass,95,8 +siasglass,95,8 +siastainedglass,95,8 +cyanglass,95,9 +cyansglass,95,9 +cyanstainedglass,95,9 +cglass,95,9 +csglass,95,9 +cstainedglass,95,9 +purpleglass,95,10 +purplesglass,95,10 +purplestainedglass,95,10 +puglass,95,10 +pusglass,95,10 +pustainedglass,95,10 +blueglass,95,11 +bluesglass,95,11 +bluestainedglass,95,11 +bluglass,95,11 +blusglass,95,11 +blustainedglass,95,11 +brownglass,95,12 +brownsglass,95,12 +brownstainedglass,95,12 +broglass,95,12 +brosglass,95,12 +brostainedglass,95,12 +darkgreenglass,95,13 +darkgreensglass,95,13 +darkgreenstainedglass,95,13 +dgreenglass,95,13 +dgreensglass,95,13 +dgreenstainedglass,95,13 +greenglass,95,13 +greensglass,95,13 +greenstainedglass,95,13 +darkgreglass,95,13 +darkgresglass,95,13 +darkgrestainedglass,95,13 +dgreglass,95,13 +dgresglass,95,13 +dgrestainedglass,95,13 +greglass,95,13 +gresglass,95,13 +grestainedglass,95,13 +redglass,95,14 +redsglass,95,14 +redstainedglass,95,14 +rglass,95,14 +rsglass,95,14 +rstainedglass,95,14 +blackglass,95,15 +blacksglass,95,15 +blackstainedglass,95,15 +blaglass,95,15 +blasglass,95,15 +blastainedglass,95,15 +trapdoor,96,0 +doortrap,96,0 +hatch,96,0 +tdoor,96,0 +doort,96,0 +trapd,96,0 +dtrap,96,0 +silverfish,97,0 +silverfishsmoothstone,97,0 +silverfishsstone,97,0 +sfishsmoothstone,97,0 +sfishsstone,97,0 +fishsmoothstone,97,0 +fishsstone,97,0 +sfsmoothstone,97,0 +sfsstone,97,0 +trapsmoothstone,97,0 +trapsstone,97,0 +monsteregg,97,0 +monstereggsmoothstone,97,0 +monstereggsstone,97,0 +meggsmoothstone,97,0 +meggsstone,97,0 +mesmoothstone,97,0 +messtone,97,0 +silverfishcobblestone,97,1 +silverfishcstone,97,1 +sfishcobblestone,97,1 +sfishcstone,97,1 +fishcobblestone,97,1 +fishcstone,97,1 +sfcobblestone,97,1 +sfcstone,97,1 +trapcobblestone,97,1 +trapcstone,97,1 +monstereggcobblestone,97,1 +monstereggcstone,97,1 +meggcobblestone,97,1 +meggcstone,97,1 +mecobblestone,97,1 +mecstone,97,1 +silverfishstonebrick,97,2 +silverfishsbrick,97,2 +sfishstonebrick,97,2 +sfishsbrick,97,2 +fishstonebrick,97,2 +fishsbrick,97,2 +sfstonebrick,97,2 +sfsbrick,97,2 +trapstonebrick,97,2 +trapsbrick,97,2 +monstereggstonebrick,97,2 +monstereggsbrick,97,2 +meggstonebrick,97,2 +meggsbrick,97,2 +mestonebrick,97,2 +mesbrick,97,2 +silverfishmossystonebrick,97,3 +silverfishmossstonebrick,97,3 +silverfishmstonebrick,97,3 +silverfishmsbrick,97,3 +sfishmossystonebrick,97,3 +sfishmossstonebrick,97,3 +sfishmstonebrick,97,3 +sfishmsbrick,97,3 +fishmossystonebrick,97,3 +fishmossstonebrick,97,3 +fishmstonebrick,97,3 +fishmsbrick,97,3 +sfmossystonebrick,97,3 +sfmossstonebrick,97,3 +sfmstonebrick,97,3 +sfmsbrick,97,3 +trapmossystonebrick,97,3 +trapmossstonebrick,97,3 +trapmstonebrick,97,3 +trapmsbrick,97,3 +monstereggmossystonebrick,97,3 +monstereggmossstonebrick,97,3 +monstereggmstonebrick,97,3 +monstereggmsbrick,97,3 +meggmossystonebrick,97,3 +meggmossstonebrick,97,3 +meggmstonebrick,97,3 +meggmsbrick,97,3 +memossystonebrick,97,3 +memossstonebrick,97,3 +memstonebrick,97,3 +memsbrick,97,3 +silverfishcrackedstonebrick,97,4 +silverfishcrackstonebrick,97,4 +silverfishcrstonebrick,97,4 +silverfishcrsbrick,97,4 +sfishcrackedstonebrick,97,4 +sfishcrackstonebrick,97,4 +sfishcrstonebrick,97,4 +sfishcrsbrick,97,4 +fishcrackedstonebrick,97,4 +fishcrackstonebrick,97,4 +fishcrstonebrick,97,4 +fishcrsbrick,97,4 +sfcrackedstonebrick,97,4 +sfcrackstonebrick,97,4 +sfcrstonebrick,97,4 +sfcrsbrick,97,4 +trapcrackedstonebrick,97,4 +trapcrackstonebrick,97,4 +trapcrstonebrick,97,4 +trapcrsbrick,97,4 +monstereggcrackedstonebrick,97,4 +monstereggcrackstonebrick,97,4 +monstereggcrstonebrick,97,4 +monstereggcrsbrick,97,4 +meggcrackedstonebrick,97,4 +meggcrackstonebrick,97,4 +meggcrstonebrick,97,4 +meggcrsbrick,97,4 +mecrackedstonebrick,97,4 +mecrackstonebrick,97,4 +mecrstonebrick,97,4 +mecrsbrick,97,4 +silverfishcirclestonebrick,97,5 +silverfishcistonebrick,97,5 +silverfishcisbrick,97,5 +sfishcirclestonebrick,97,5 +sfishcistonebrick,97,5 +sfishcisbrick,97,5 +fishcirclestonebrick,97,5 +fishcistonebrick,97,5 +fishcisbrick,97,5 +sfcirclestonebrick,97,5 +sfcistonebrick,97,5 +sfcisbrick,97,5 +trapcirclestonebrick,97,5 +trapcistonebrick,97,5 +trapcisbrick,97,5 +monstereggcirclestonebrick,97,5 +monstereggcistonebrick,97,5 +monstereggcisbrick,97,5 +meggcirclestonebrick,97,5 +meggcistonebrick,97,5 +meggcisbrick,97,5 +mecirclestonebrick,97,5 +mecistonebrick,97,5 +mecisbrick,97,5 +stonebrick,98,0 +stonebricks,98,0 +stonebrickblock,98,0 +stonebb,98,0 +sbrick,98,0 +mossystonebrick,98,1 +mossystonebricks,98,1 +mossystonebrickblock,98,1 +mossystonebb,98,1 +mossstonebrick,98,1 +mossstonebricks,98,1 +mossstonebrickblock,98,1 +mossstonebb,98,1 +mstonebrick,98,1 +mstonebricks,98,1 +mstonebrickblock,98,1 +mstonebb,98,1 +mosssbrick,98,1 +mosssbricks,98,1 +mosssbrickblock,98,1 +mosssbb,98,1 +msbrick,98,1 +msbricks,98,1 +msbrickblock,98,1 +crackedstone,98,2 +crackedstonebrick,98,2 +crackedstonebricks,98,2 +crackedstonebrickblock,98,2 +crackedstonebb,98,2 +crackstonebrick,98,2 +crackstonebricks,98,2 +crackstonebrickblock,98,2 +crackstonebb,98,2 +crstonebrick,98,2 +crstonebricks,98,2 +crstonebrickblock,98,2 +crstonebb,98,2 +cracksbrick,98,2 +cracksbricks,98,2 +cracksbrickblock,98,2 +cracksbb,98,2 +crsbrick,98,2 +crsbricks,98,2 +crsbrickblock,98,2 +circlestone,98,3 +circlestonebrick,98,3 +circlestonebricks,98,3 +circlestonebrickblock,98,3 +circlestonebb,98,3 +cistonebrick,98,3 +cistonebricks,98,3 +cistonebrickblock,98,3 +cistonebb,98,3 +circlesbrick,98,3 +circlesbricks,98,3 +circlesbrickblock,98,3 +circlesbb,98,3 +cisbrick,98,3 +cisbricks,98,3 +cisbrickblock,98,3 +giantredmushroom,99,0 +hugeredmushroom,99,0 +bigredmushroom,99,0 +gredmushroom,99,0 +hredmushroom,99,0 +bredmushroom,99,0 +giantrmushroom,99,0 +hugermushroom,99,0 +bigrmushroom,99,0 +grmushroom,99,0 +hrmushroom,99,0 +brmushroom,99,0 +giantredmush,99,0 +hugeredmush,99,0 +bigredmush,99,0 +gredmush,99,0 +hredmush,99,0 +bredmush,99,0 +giantrmush,99,0 +hugermush,99,0 +bigrmush,99,0 +grmush,99,0 +hrmush,99,0 +brmush,99,0 +giantbrownmushroom,100,0 +hugebrownmushroom,100,0 +bigbrownmushroom,100,0 +gbrownmushroom,100,0 +hbrownmushroom,100,0 +bbrownmushroom,100,0 +giantbmushroom,100,0 +hugebmushroom,100,0 +bigbmushroom,100,0 +gbmushroom,100,0 +hbmushroom,100,0 +bbmushroom,100,0 +giantbrownmush,100,0 +hugebrownmush,100,0 +bigbrownmush,100,0 +gbrownmush,100,0 +hbrownmush,100,0 +bbrownmush,100,0 +giantbmush,100,0 +hugebmush,100,0 +bigbmush,100,0 +gbmush,100,0 +hbmush,100,0 +bbmush,100,0 +ironbars,101,0 +ironbarsb,101,0 +ironbarsblock,101,0 +ironfence,101,0 +metalbars,101,0 +metalbarsb,101,0 +metalbarsblock,101,0 +metalfence,101,0 +jailbars,101,0 +jailbarsb,101,0 +jailbarsblock,101,0 +jailfence,101,0 +mbars,101,0 +mbarsb,101,0 +mbarsblock,101,0 +mfence,101,0 +jbars,101,0 +jbarsb,101,0 +jbarsblock,101,0 +jfence,101,0 +ibars,101,0 +ibarsb,101,0 +ibarsblock,101,0 +ifence,101,0 +glasspane,102,0 +glassp,102,0 +paneglass,102,0 +pglass,102,0 +flatglass,102,0 +fglass,102,0 +skinnyglass,102,0 +glassflat,102,0 +glassf,102,0 +glassskinny,102,0 +glasss,102,0 +melon,103,0 +watermelon,103,0 +greenmelon,103,0 +melongreen,103,0 +melonblock,103,0 +watermelonblock,103,0 +greenmelonblock,103,0 +vines,106,0 +vine,106,0 +greenvines,106,0 +greenvine,106,0 +gardenvines,106,0 +gardenvine,106,0 +vinesgreen,106,0 +vinegreen,106,0 +vinesgarden,106,0 +vinegarden,106,0 +vinesg,106,0 +vineg,106,0 +gvines,106,0 +gvine,106,0 +woodgate,107,0 +woodenfencegate,107,0 +wfencegate,107,0 +woodfencegate,107,0 +woodengate,107,0 +wgate,107,0 +gate,107,0 +gardengate,107,0 +ggate,107,0 +fencegate,107,0 +fgate,107,0 +brickstairs,108,0 +redbrickstairs,108,0 +redbstairs,108,0 +rbrickstairs,108,0 +bstairs,108,0 +redstairs,108,0 +brickstair,108,0 +redbrickstair,108,0 +redbstair,108,0 +rbrickstair,108,0 +bstair,108,0 +redstair,108,0 +stonebrickstairs,109,0 +stonebstairs,109,0 +sbstairs,109,0 +cementbrickstairs,109,0 +cementstairs,109,0 +cementbstairs,109,0 +cbstairs,109,0 +greybrickstairs,109,0 +greybstairs,109,0 +greystairs,109,0 +mycelium,110,0 +purplegrass,110,0 +pinkgrass,110,0 +mycel,110,0 +swampgrass,110,0 +sgrass,110,0 +mushroomgrass,110,0 +mushgrass,110,0 +lilypad,111,0 +waterlily,111,0 +lily,111,0 +swamppad,111,0 +lpad,111,0 +wlily,111,0 +netherbrickblock,112,0 +hellbrickblock,112,0 +deathbrickblock,112,0 +nbrickblock,112,0 +hbrickblock,112,0 +dbrickblock,112,0 +netherbblock,112,0 +hellbblock,112,0 +deathbblock,112,0 +nbblock,112,0 +hbblock,112,0 +dbblock,112,0 +netherbrickfence,113,0 +hellbrickfence,113,0 +nbrickfence,113,0 +hbrickfence,113,0 +netherbfence,113,0 +hellbfence,113,0 +netherfence,113,0 +hellfence,113,0 +nbfence,113,0 +hbfence,113,0 +nfence,113,0 +hfence,113,0 +netherbrickstairs,114,0 +hellbrickstairs,114,0 +nbrickstairs,114,0 +hbrickstairs,114,0 +netherbstairs,114,0 +hellbstairs,114,0 +netherstairs,114,0 +hellstairs,114,0 +nbstairs,114,0 +hbstairs,114,0 +nstairs,114,0 +hstairs,114,0 +netherbrickstair,114,0 +hellbrickstair,114,0 +nbrickstair,114,0 +hbrickstair,114,0 +netherbstair,114,0 +hellbstair,114,0 +netherstair,114,0 +hellstair,114,0 +nbstair,114,0 +hbstair,114,0 +nstair,114,0 +hstair,114,0 +enchantmenttable,116,0 +enchantingtable,116,0 +enchanttable,116,0 +etable,116,0 +magicaltable,116,0 +magictable,116,0 +mtable,116,0 +enchantmentdesk,116,0 +enchantingdesk,116,0 +enchantdesk,116,0 +edesk,116,0 +magicaldesk,116,0 +magicdesk,116,0 +mdesk,116,0 +booktable,116,0 +bookdesk,116,0 +btable,116,0 +bdesk,116,0 +enderportal,119,0 +endergoo,119,0 +endgoo,119,0 +endportal,119,0 +egoo,119,0 +eportal,119,0 +enderportalframe,120,0 +endportalframe,120,0 +endgooframe,120,0 +endergooframe,120,0 +egooframe,120,0 +eportalframe,120,0 +enderframe,120,0 +endframe,120,0 +enderstone,121,0 +endstone,121,0 +endrock,121,0 +enderrock,121,0 +erock,121,0 +estone,121,0 +enderdragonegg,122,0 +endegg,122,0 +dragonegg,122,0 +degg,122,0 +bossegg,122,0 +begg,122,0 +redstonelamp,123,0 +redlamp,123,0 +rslamp,123,0 +woodendoublestep,125,0 +woodendstep,125,0 +wooddoublestep,125,0 +wooddstep,125,0 +wdoublestep,125,0 +wdstep,125,0 +doublewoodenstep,125,0 +dwoodenstep,125,0 +doublewoodstep,125,0 +dwoodstep,125,0 +doublewstep,125,0 +dwstep,125,0 +woodendoubleslab,125,0 +woodendslab,125,0 +wooddoubleslab,125,0 +wooddslab,125,0 +wdoubleslab,125,0 +wdslab,125,0 +doublewoodenslab,125,0 +dwoodenslab,125,0 +doublewoodslab,125,0 +dwoodslab,125,0 +doublewslab,125,0 +dwslab,125,0 +woodendoublehalfblock,125,0 +woodendhalfblock,125,0 +wooddoublehalfblock,125,0 +wooddhalfblock,125,0 +wdoublehalfblock,125,0 +wdhalfblock,125,0 +doublewoodenhalfblock,125,0 +dwoodenhalfblock,125,0 +doublewoodhalfblock,125,0 +dwoodhalfblock,125,0 +doublewhalfblock,125,0 +dwhalfblock,125,0 +oakwoodendoublehalfblock,125,0 +oakwoodendhalfblock,125,0 +oakwooddoublehalfblock,125,0 +oakwooddhalfblock,125,0 +oakwdoublehalfblock,125,0 +oakwdhalfblock,125,0 +oakdoublewoodenhalfblock,125,0 +oakdwoodenhalfblock,125,0 +oakdoublewoodhalfblock,125,0 +oakdwoodhalfblock,125,0 +oakdoublewhalfblock,125,0 +oakdwhalfblock,125,0 +oakdoublehalfblock,125,0 +oakdhalfblock,125,0 +odhalfblock,125,0 +oakwoodendoublestep,125,0 +oakwoodendstep,125,0 +oakwooddoublestep,125,0 +oakwooddstep,125,0 +oakwdoublestep,125,0 +oakwdstep,125,0 +oakdoublewoodenstep,125,0 +oakdwoodenstep,125,0 +oakdoublewoodstep,125,0 +oakdwoodstep,125,0 +oakdoublewstep,125,0 +oakdwstep,125,0 +oakdoublestep,125,0 +oakdstep,125,0 +odstep,125,0 +oakwoodendoubleslab,125,0 +oakwoodendslab,125,0 +oakwooddoubleslab,125,0 +oakwooddslab,125,0 +oakwdoubleslab,125,0 +oakwdslab,125,0 +oakdoublewoodenslab,125,0 +oakdwoodenslab,125,0 +oakdoublewoodslab,125,0 +oakdwoodslab,125,0 +oakdoublewslab,125,0 +oakdwslab,125,0 +oakdoubleslab,125,0 +oakdslab,125,0 +odslab,125,0 +sprucewoodendoublestep,125,1 +sprucewoodendstep,125,1 +sprucewooddoublestep,125,1 +sprucewooddstep,125,1 +sprucewdoublestep,125,1 +sprucewdstep,125,1 +sprucedoublewoodenstep,125,1 +sprucedwoodenstep,125,1 +sprucedoublewoodstep,125,1 +sprucedwoodstep,125,1 +sprucedoublewstep,125,1 +sprucedwstep,125,1 +sprucedoublestep,125,1 +sprucedstep,125,1 +sprucewoodendoubleslab,125,1 +sprucewoodendslab,125,1 +sprucewooddoubleslab,125,1 +sprucewooddslab,125,1 +sprucewdoubleslab,125,1 +sprucewdslab,125,1 +sprucedoublewoodenslab,125,1 +sprucedwoodenslab,125,1 +sprucedoublewoodslab,125,1 +sprucedwoodslab,125,1 +sprucedoublewslab,125,1 +sprucedwslab,125,1 +sprucedoubleslab,125,1 +sprucedslab,125,1 +sprucewoodendoublehalfblock,125,1 +sprucewoodendhalfblock,125,1 +sprucewooddoublehalfblock,125,1 +sprucewooddhalfblock,125,1 +sprucewdoublehalfblock,125,1 +sprucewdhalfblock,125,1 +sprucedoublewoodenhalfblock,125,1 +sprucedwoodenhalfblock,125,1 +sprucedoublewoodhalfblock,125,1 +sprucedwoodhalfblock,125,1 +sprucedoublewhalfblock,125,1 +sprucedwhalfblock,125,1 +sprucedoublehalfblock,125,1 +sprucedhalfblock,125,1 +darkwoodendoublestep,125,1 +darkwoodendstep,125,1 +darkwooddoublestep,125,1 +darkwooddstep,125,1 +darkwdoublestep,125,1 +darkwdstep,125,1 +darkdoublewoodenstep,125,1 +darkdwoodenstep,125,1 +darkdoublewoodstep,125,1 +darkdwoodstep,125,1 +darkdoublewstep,125,1 +darkdwstep,125,1 +darkdoublestep,125,1 +darkdstep,125,1 +ddstep,125,1 +darkwoodendoubleslab,125,1 +darkwoodendslab,125,1 +darkwooddoubleslab,125,1 +darkwooddslab,125,1 +darkwdoubleslab,125,1 +darkwdslab,125,1 +darkdoublewoodenslab,125,1 +darkdwoodenslab,125,1 +darkdoublewoodslab,125,1 +darkdwoodslab,125,1 +darkdoublewslab,125,1 +darkdwslab,125,1 +darkdoubleslab,125,1 +darkdslab,125,1 +ddslab,125,1 +darkwoodendoublehalfblock,125,1 +darkwoodendhalfblock,125,1 +darkwooddoublehalfblock,125,1 +darkwooddhalfblock,125,1 +darkwdoublehalfblock,125,1 +darkwdhalfblock,125,1 +darkdoublewoodenhalfblock,125,1 +darkdwoodenhalfblock,125,1 +darkdoublewoodhalfblock,125,1 +darkdwoodhalfblock,125,1 +darkdoublewhalfblock,125,1 +darkdwhalfblock,125,1 +darkdoublehalfblock,125,1 +darkdhalfblock,125,1 +ddhalfblock,125,1 +birchwoodendoublestep,125,2 +birchwoodendstep,125,2 +birchwooddoublestep,125,2 +birchwooddstep,125,2 +birchwdoublestep,125,2 +birchwdstep,125,2 +birchdoublewoodenstep,125,2 +birchdwoodenstep,125,2 +birchdoublewoodstep,125,2 +birchdwoodstep,125,2 +birchdoublewstep,125,2 +birchdwstep,125,2 +birchdoublestep,125,2 +birchdstep,125,2 +birchwoodendoubleslab,125,2 +birchwoodendslab,125,2 +birchwooddoubleslab,125,2 +birchwooddslab,125,2 +birchwdoubleslab,125,2 +birchwdslab,125,2 +birchdoublewoodenslab,125,2 +birchdwoodenslab,125,2 +birchdoublewoodslab,125,2 +birchdwoodslab,125,2 +birchdoublewslab,125,2 +birchdwslab,125,2 +birchdoubleslab,125,2 +birchdslab,125,2 +birchwoodendoublehalfblock,125,2 +birchwoodendhalfblock,125,2 +birchwooddoublehalfblock,125,2 +birchwooddhalfblock,125,2 +birchwdoublehalfblock,125,2 +birchwdhalfblock,125,2 +birchdoublewoodenhalfblock,125,2 +birchdwoodenhalfblock,125,2 +birchdoublewoodhalfblock,125,2 +birchdwoodhalfblock,125,2 +birchdoublewhalfblock,125,2 +birchdwhalfblock,125,2 +birchdoublehalfblock,125,2 +birchdhalfblock,125,2 +lightwoodendoublehalfblock,125,2 +lightwoodendhalfblock,125,2 +lightwooddoublehalfblock,125,2 +lightwooddhalfblock,125,2 +lightwdoublehalfblock,125,2 +lightwdhalfblock,125,2 +lightdoublewoodenhalfblock,125,2 +lightdwoodenhalfblock,125,2 +lightdoublewoodhalfblock,125,2 +lightdwoodhalfblock,125,2 +lightdoublewhalfblock,125,2 +lightdwhalfblock,125,2 +lightdoublehalfblock,125,2 +lightdhalfblock,125,2 +ldhalfblock,125,2 +lightwoodendoublestep,125,2 +lightwoodendstep,125,2 +lightwooddoublestep,125,2 +lightwooddstep,125,2 +lightwdoublestep,125,2 +lightwdstep,125,2 +lightdoublewoodenstep,125,2 +lightdwoodenstep,125,2 +lightdoublewoodstep,125,2 +lightdwoodstep,125,2 +lightdoublewstep,125,2 +lightdwstep,125,2 +lightdoublestep,125,2 +lightdstep,125,2 +ldstep,125,2 +lightwoodendoubleslab,125,2 +lightwoodendslab,125,2 +lightwooddoubleslab,125,2 +lightwooddslab,125,2 +lightwdoubleslab,125,2 +lightwdslab,125,2 +lightdoublewoodenslab,125,2 +lightdwoodenslab,125,2 +lightdoublewoodslab,125,2 +lightdwoodslab,125,2 +lightdoublewslab,125,2 +lightdwslab,125,2 +lightdoubleslab,125,2 +lightdslab,125,2 +ldslab,125,2 +junglewoodendoublestep,125,3 +junglewoodendstep,125,3 +junglewooddoublestep,125,3 +junglewooddstep,125,3 +junglewdoublestep,125,3 +junglewdstep,125,3 +jungledoublewoodenstep,125,3 +jungledwoodenstep,125,3 +jungledoublewoodstep,125,3 +jungledwoodstep,125,3 +jungledoublewstep,125,3 +jungledwstep,125,3 +jungledoublestep,125,3 +jungledstep,125,3 +jdstep,125,3 +junglewoodendoubleslab,125,3 +junglewoodendslab,125,3 +junglewooddoubleslab,125,3 +junglewooddslab,125,3 +junglewdoubleslab,125,3 +junglewdslab,125,3 +jungledoublewoodenslab,125,3 +jungledwoodenslab,125,3 +jungledoublewoodslab,125,3 +jungledwoodslab,125,3 +jungledoublewslab,125,3 +jungledwslab,125,3 +jungledoubleslab,125,3 +jungledslab,125,3 +jdslab,125,3 +junglewoodendoublehalfblock,125,3 +junglewoodendhalfblock,125,3 +junglewooddoublehalfblock,125,3 +junglewooddhalfblock,125,3 +junglewdoublehalfblock,125,3 +junglewdhalfblock,125,3 +jungledoublewoodenhalfblock,125,3 +jungledwoodenhalfblock,125,3 +jungledoublewoodhalfblock,125,3 +jungledwoodhalfblock,125,3 +jungledoublewhalfblock,125,3 +jungledwhalfblock,125,3 +jungledoublehalfblock,125,3 +jungledhalfblock,125,3 +jdhalfblock,125,3 +forestwoodendoublehalfblock,125,3 +forestwoodendhalfblock,125,3 +forestwooddoublehalfblock,125,3 +forestwooddhalfblock,125,3 +forestwdoublehalfblock,125,3 +forestwdhalfblock,125,3 +forestdoublewoodenhalfblock,125,3 +forestdwoodenhalfblock,125,3 +forestdoublewoodhalfblock,125,3 +forestdwoodhalfblock,125,3 +forestdoublewhalfblock,125,3 +forestdwhalfblock,125,3 +forestdoublehalfblock,125,3 +forestdhalfblock,125,3 +fdhalfblock,125,3 +forestwoodendoublestep,125,3 +forestwoodendstep,125,3 +forestwooddoublestep,125,3 +forestwooddstep,125,3 +forestwdoublestep,125,3 +forestwdstep,125,3 +forestdoublewoodenstep,125,3 +forestdwoodenstep,125,3 +forestdoublewoodstep,125,3 +forestdwoodstep,125,3 +forestdoublewstep,125,3 +forestdwstep,125,3 +forestdoublestep,125,3 +forestdstep,125,3 +fdstep,125,3 +forestwoodendoubleslab,125,3 +forestwoodendslab,125,3 +forestwooddoubleslab,125,3 +forestwooddslab,125,3 +forestwdoubleslab,125,3 +forestwdslab,125,3 +forestdoublewoodenslab,125,3 +forestdwoodenslab,125,3 +forestdoublewoodslab,125,3 +forestdwoodslab,125,3 +forestdoublewslab,125,3 +forestdwslab,125,3 +forestdoubleslab,125,3 +forestdslab,125,3 +fdslab,125,3 +acaciawoodendoublestep,125,4 +acaciawoodendstep,125,4 +acaciawooddoublestep,125,4 +acaciawooddstep,125,4 +acaciawdoublestep,125,4 +acaciawdstep,125,4 +acaciadoublewoodenstep,125,4 +acaciadwoodenstep,125,4 +acaciadoublewoodstep,125,4 +acaciadwoodstep,125,4 +acaciadoublewstep,125,4 +acaciadwstep,125,4 +acaciadoublestep,125,4 +acaciadstep,125,4 +adstep,125,4 +acaciawoodendoubleslab,125,4 +acaciawoodendslab,125,4 +acaciawooddoubleslab,125,4 +acaciawooddslab,125,4 +acaciawdoubleslab,125,4 +acaciawdslab,125,4 +acaciadoublewoodenslab,125,4 +acaciadwoodenslab,125,4 +acaciadoublewoodslab,125,4 +acaciadwoodslab,125,4 +acaciadoublewslab,125,4 +acaciadwslab,125,4 +acaciadoubleslab,125,4 +acaciadslab,125,4 +adslab,125,4 +acaciawoodendoublehalfblock,125,4 +acaciawoodendhalfblock,125,4 +acaciawooddoublehalfblock,125,4 +acaciawooddhalfblock,125,4 +acaciawdoublehalfblock,125,4 +acaciawdhalfblock,125,4 +acaciadoublewoodenhalfblock,125,4 +acaciadwoodenhalfblock,125,4 +acaciadoublewoodhalfblock,125,4 +acaciadwoodhalfblock,125,4 +acaciadoublewhalfblock,125,4 +acaciadwhalfblock,125,4 +acaciadoublehalfblock,125,4 +acaciadhalfblock,125,4 +adhalfblock,125,4 +darkoakwoodendoublehalfblock,125,5 +darkoakwoodendhalfblock,125,5 +darkoakwooddoublehalfblock,125,5 +darkoakwooddhalfblock,125,5 +darkoakwdoublehalfblock,125,5 +darkoakwdhalfblock,125,5 +darkoakdoublewoodenhalfblock,125,5 +darkoakdwoodenhalfblock,125,5 +darkoakdoublewoodhalfblock,125,5 +darkoakdwoodhalfblock,125,5 +darkoakdoublewhalfblock,125,5 +darkoakdwhalfblock,125,5 +darkoakdoublehalfblock,125,5 +darkoakdhalfblock,125,5 +dodhalfblock,125,5 +darkoakwoodendoublestep,125,5 +darkoakwoodendstep,125,5 +darkoakwooddoublestep,125,5 +darkoakwooddstep,125,5 +darkoakwdoublestep,125,5 +darkoakwdstep,125,5 +darkoakdoublewoodenstep,125,5 +darkoakdwoodenstep,125,5 +darkoakdoublewoodstep,125,5 +darkoakdwoodstep,125,5 +darkoakdoublewstep,125,5 +darkoakdwstep,125,5 +darkoakdoublestep,125,5 +darkoakdstep,125,5 +dodstep,125,5 +darkoakwoodendoubleslab,125,5 +darkoakwoodendslab,125,5 +darkoakwooddoubleslab,125,5 +darkoakwooddslab,125,5 +darkoakwdoubleslab,125,5 +darkoakwdslab,125,5 +darkoakdoublewoodenslab,125,5 +darkoakdwoodenslab,125,5 +darkoakdoublewoodslab,125,5 +darkoakdwoodslab,125,5 +darkoakdoublewslab,125,5 +darkoakdwslab,125,5 +darkoakdoubleslab,125,5 +darkoakdslab,125,5 +dodslab,125,5 +woodenstep,126,0 +woodstep,126,0 +wstep,126,0 +woodenslab,126,0 +woodslab,126,0 +wslab,126,0 +woodenhalfblock,126,0 +woodhalfblock,126,0 +whalfblock,126,0 +oakwoodenstep,126,0 +oakwoodstep,126,0 +oakwstep,126,0 +oakstep,126,0 +ostep,126,0 +oakwoodenslab,126,0 +oakwoodslab,126,0 +oakwslab,126,0 +oakslab,126,0 +oslab,126,0 +oakwoodenhalfblock,126,0 +oakwoodhalfblock,126,0 +oakwhalfblock,126,0 +oakhalfblock,126,0 +ohalfblock,126,0 +sprucewoodenstep,126,1 +sprucewoodstep,126,1 +sprucewstep,126,1 +sprucestep,126,1 +sprucewoodenslab,126,1 +sprucewoodslab,126,1 +sprucewslab,126,1 +spruceslab,126,1 +sprucewoodenhalfblock,126,1 +sprucewoodhalfblock,126,1 +sprucewhalfblock,126,1 +sprucehalfblock,126,1 +darkwoodenstep,126,1 +darkwoodstep,126,1 +darkwstep,126,1 +darkstep,126,1 +darkwoodenslab,126,1 +darkwoodslab,126,1 +darkwslab,126,1 +darkslab,126,1 +darkwoodenhalfblock,126,1 +darkwoodhalfblock,126,1 +darkwhalfblock,126,1 +darkhalfblock,126,1 +birchwoodenstep,126,2 +birchwoodstep,126,2 +birchwstep,126,2 +birchstep,126,2 +birchwoodenslab,126,2 +birchwoodslab,126,2 +birchwslab,126,2 +birchslab,126,2 +birchwoodenhalfblock,126,2 +birchwoodhalfblock,126,2 +birchwhalfblock,126,2 +birchhalfblock,126,2 +lightwoodenstep,126,2 +lightwoodstep,126,2 +lightwstep,126,2 +lightstep,126,2 +lstep,126,2 +lightwoodenslab,126,2 +lightwoodslab,126,2 +lightwslab,126,2 +lightslab,126,2 +lslab,126,2 +lightwoodenhalfblock,126,2 +lightwoodhalfblock,126,2 +lightwhalfblock,126,2 +lighthalfblock,126,2 +lhalfblock,126,2 +junglewoodenstep,126,3 +junglewoodstep,126,3 +junglewstep,126,3 +junglestep,126,3 +jstep,126,3 +junglewoodenslab,126,3 +junglewoodslab,126,3 +junglewslab,126,3 +jungleslab,126,3 +jslab,126,3 +junglewoodenhalfblock,126,3 +junglewoodhalfblock,126,3 +junglewhalfblock,126,3 +junglehalfblock,126,3 +jhalfblock,126,3 +forestwoodenstep,126,3 +forestwoodstep,126,3 +forestwstep,126,3 +foreststep,126,3 +fstep,126,3 +forestwoodenslab,126,3 +forestwoodslab,126,3 +forestwslab,126,3 +forestslab,126,3 +fslab,126,3 +forestwoodenhalfblock,126,3 +forestwoodhalfblock,126,3 +forestwhalfblock,126,3 +foresthalfblock,126,3 +fhalfblock,126,3 +acaciawoodenstep,126,4 +acaciawoodstep,126,4 +acaciawstep,126,4 +acaciastep,126,4 +astep,126,4 +acaciawoodenslab,126,4 +acaciawoodslab,126,4 +acaciawslab,126,4 +acaciaslab,126,4 +aslab,126,4 +acaciawoodenhalfblock,126,4 +acaciawoodhalfblock,126,4 +acaciawhalfblock,126,4 +acaciahalfblock,126,4 +ahalfblock,126,4 +darkoakwoodenstep,126,5 +darkoakwoodstep,126,5 +darkoakwstep,126,5 +darkoakstep,126,5 +dostep,126,5 +darkoakwoodenslab,126,5 +darkoakwoodslab,126,5 +darkoakwslab,126,5 +darkoakslab,126,5 +doslab,126,5 +darkoakwoodenhalfblock,126,5 +darkoakwoodhalfblock,126,5 +darkoakwhalfblock,126,5 +darkoakhalfblock,126,5 +dohalfblock,126,5 +cocoaplant,127,0 +cocoplant,127,0 +cplant,127,0 +cocoafruit,127,0 +cocofruit,127,0 +cfruit,127,0 +cocoapod,127,0 +cocopod,127,0 +cpod,127,0 +sandstonestairs,128,0 +sandstairs,128,0 +sandsstairs,128,0 +sstonestairs,128,0 +ssstairs,128,0 +sandstair,128,0 +sandstonestair,128,0 +sandsstair,128,0 +sstonestair,128,0 +ssstair,128,0 +emeraldore,129,0 +eore,129,0 +oreemerald,129,0 +oree,129,0 +enderchest,130,0 +endchest,130,0 +echest,130,0 +chestender,130,0 +chestend,130,0 +cheste,130,0 +endercontainer,130,0 +endcontainer,130,0 +econtainer,130,0 +tripwirehook,131,0 +tripwire,131,0 +trip,131,0 +tripwirelever,131,0 +triphook,131,0 +emeraldblock,133,0 +blockemerald,133,0 +eblock,133,0 +blocke,133,0 +sprucewoodenstairs,134,0 +sprucewoodstairs,134,0 +sprucewstairs,134,0 +sprucestairs,134,0 +darkwoodenstairs,134,0 +darkwoodstairs,134,0 +darkwstairs,134,0 +darkstairs,134,0 +dstairs,134,0 +sprucewoodenstair,134,0 +sprucewoodstair,134,0 +sprucewstair,134,0 +sprucestair,134,0 +darkwoodenstair,134,0 +darkwoodstair,134,0 +darkwstair,134,0 +darkstair,134,0 +dstair,134,0 +birchwoodenstairs,135,0 +birchwoodstairs,135,0 +birchwstairs,135,0 +birchstairs,135,0 +lightwoodenstairs,135,0 +lightwoodstairs,135,0 +lightwstairs,135,0 +lightstairs,135,0 +lstairs,135,0 +birchwoodenstair,135,0 +birchwoodstair,135,0 +birchwstair,135,0 +birchstair,135,0 +lightwoodenstair,135,0 +lightwoodstair,135,0 +lightwstair,135,0 +lightstair,135,0 +lstair,135,0 +junglewoodenstairs,136,0 +junglewoodstairs,136,0 +junglewstairs,136,0 +junglestairs,136,0 +jstairs,136,0 +forestwoodenstairs,136,0 +forestwoodstairs,136,0 +forestwstairs,136,0 +foreststairs,136,0 +fstairs,136,0 +junglewoodenstair,136,0 +junglewoodstair,136,0 +junglewstair,136,0 +junglestair,136,0 +jstair,136,0 +forestwoodenstair,136,0 +forestwoodstair,136,0 +forestwstair,136,0 +foreststair,136,0 +fstair,136,0 +commandblock,137,0 +blockcommand,137,0 +cmdblock,137,0 +blockcmd,137,0 +macroblock,137,0 +blockmacro,137,0 +beacon,138,0 +beaconblock,138,0 +cobblestonewall,139,0 +cstonewall,139,0 +cobblewall,139,0 +cobblestonefence,139,0 +cstonefence,139,0 +cobblefence,139,0 +cswall,139,0 +csfence,139,0 +cwall,139,0 +cfence,139,0 +mosscobblestonewall,139,1 +mosscstonewall,139,1 +mosscobblewall,139,1 +mcobblestonewall,139,1 +mcstonewall,139,1 +mcobblewall,139,1 +mosscobblestonefence,139,1 +mosscstonefence,139,1 +mosscobblefence,139,1 +mcobblestonefence,139,1 +mcstonefence,139,1 +mcobblefence,139,1 +mcswall,139,0 +mcsfence,139,0 +mcwall,139,0 +mcfence,139,0 +plantedcarrot,141,0 +plantcarrot,141,0 +carrots,141,0 +growingcarrot,141,0 +potatoplant,142,0 +potatoes,142,0 +plantedpotato,142,0 +plantpotato,142,0 +growingpotato,142,0 +woodenbutton,143,0 +woodenplankbutton,143,0 +woodplankbutton,143,0 +wplankbutton,143,0 +plankbutton,143,0 +woodbutton,143,0 +wbutton,143,0 +anvil,145,0 +slightlydamagedanvil,145,1 +slightdamageanvil,145,1 +damagedanvil,145,1 +verydamagedanvil,145,2 +trapchest,146,0 +trappedchest,146,0 +chesttrapped,146,0 +chesttrap,146,0 +goldpressureplate,147,0 +weightedgoldpressureplate,147,0 +weightgoldpressureplate,147,0 +wgoldpressureplate,147,0 +weightedgoldpressplate,147,0 +weightgoldpressplate,147,0 +wgoldpressplate,147,0 +goldpressplate,147,0 +weightedgoldpplate,147,0 +weightgoldpplate,147,0 +wgoldpplate,147,0 +goldpplate,147,0 +weightedgoldplate,147,0 +weightgoldplate,147,0 +wgoldplate,147,0 +goldplate,147,0 +weightedgpressureplate,147,0 +weightgpressureplate,147,0 +wgpressureplate,147,0 +gpressureplate,147,0 +weightedgpressplate,147,0 +weightgpressplate,147,0 +wgpressplate,147,0 +gpressplate,147,0 +weightedgpplate,147,0 +weightgpplate,147,0 +wgpplate,147,0 +gpplate,147,0 +weightedgplate,147,0 +weightgplate,147,0 +wgplate,147,0 +gplate,147,0 +ironpressureplate,148,0 +weightedironpressureplate,148,0 +weightironpressureplate,148,0 +wironpressureplate,148,0 +weightedironpressplate,148,0 +weightironpressplate,148,0 +wironpressplate,148,0 +ironpressplate,148,0 +weightedironpplate,148,0 +weightironpplate,148,0 +wironpplate,148,0 +ironpplate,148,0 +weightedironplate,148,0 +weightironplate,148,0 +wironplate,148,0 +ironplate,148,0 +weightedipressureplate,148,0 +weightipressureplate,148,0 +wipressureplate,148,0 +ipressureplate,148,0 +weightedipressplate,148,0 +weightipressplate,148,0 +wipressplate,148,0 +ipressplate,148,0 +weightedipplate,148,0 +weightipplate,148,0 +wipplate,148,0 +ipplate,148,0 +weightediplate,148,0 +weightiplate,148,0 +wiplate,148,0 +iplate,148,0 +daylightsensor,151,0 +daylightsense,151,0 +lightsensor,151,0 +lightsense,151,0 +daysensor,151,0 +daysense,151,0 +timesensor,151,0 +timesense,151,0 +redstoneblock,152,0 +rstoneblock,152,0 +redsblock,152,0 +rsblock,152,0 +blockredstone,152,0 +blockrstone,152,0 +blockreds,152,0 +blockrs,152,0 +netherquartzore,153,0 +hellquartzore,153,0 +deathquartzore,153,0 +nquartzore,153,0 +hquartzore,153,0 +dquartzore,153,0 +quartzore,153,0 +netherqore,153,0 +hellqore,153,0 +deathqore,153,0 +nqore,153,0 +hqore,153,0 +dqore,153,0 +qore,153,0 +hopper,154,0 +chestpuller,154,0 +chestpull,154,0 +cheststorer,154,0 +cheststore,154,0 +itempuller,154,0 +itempull,154,0 +itemstorer,154,0 +itemstore,154,0 +quartzblock,155,0 +netherquartzblock,155,0 +nqblock,155,0 +qblock,155,0 +chiseledquartzblock,155,1 +chiselquartzblock,155,1 +cquartzblock,155,1 +cqblock,155,1 +pillarquartzblock,155,2 +pquartzblock,155,2 +pqblock,155,2 +quartzstairs,156,0 +qstairs,156,0 +quartzstair,156,0 +qstair,156,0 +activatorrails,157,0 +activaterails,157,0 +triggerrails,157,0 +arails,157,0 +trails,157,0 +activatorrail,157,0 +activaterail,157,0 +triggerrail,157,0 +arail,157,0 +trail,157,0 +activatortrack,157,0 +activatetrack,157,0 +triggertrack,157,0 +atrack,157,0 +ttrack,157,0 +dropper,158,0 +drop,158,0 +chestdispenser,158,0 +chestdispense,158,0 +chestdropper,158,0 +chestdrop,158,0 +whiteclay,159,0 +whitesclay,159,0 +whitestainedclay,159,0 +wclay,159,0 +wsclay,159,0 +wstainedclay,159,0 +sclay,159,0 +stainedclay,159,0 +orangeclay,159,1 +orangesclay,159,1 +orangestainedclay,159,1 +oclay,159,1 +osclay,159,1 +ostainedclay,159,1 +magentaclay,159,2 +magentasclay,159,2 +magentastainedclay,159,2 +mclay,159,2 +msclay,159,2 +mstainedclay,159,2 +lightblueclay,159,3 +lightbluesclay,159,3 +lightbluestainedclay,159,3 +lblueclay,159,3 +lbluesclay,159,3 +lbluestainedclay,159,3 +lightbluclay,159,3 +lightblusclay,159,3 +lightblustainedclay,159,3 +lbluclay,159,3 +lblusclay,159,3 +lblustainedclay,159,3 +lbclay,159,3 +lbsclay,159,3 +lbstainedclay,159,3 +yellowclay,159,4 +yellowsclay,159,4 +yellowstainedclay,159,4 +yclay,159,4 +ysclay,159,4 +ystainedclay,159,4 +lightgreenclay,159,5 +lightgreensclay,159,5 +lightgreenstainedclay,159,5 +lgreenclay,159,5 +lgreensclay,159,5 +lgreenstainedclay,159,5 +lightgreclay,159,5 +lightgresclay,159,5 +lightgrestainedclay,159,5 +lgreclay,159,5 +lgresclay,159,5 +lgrestainedclay,159,5 +limeclay,159,5 +limesclay,159,5 +limestainedclay,159,5 +lclay,159,5 +lsclay,159,5 +lstainedclay,159,5 +pinkclay,159,6 +pinksclay,159,6 +pinkstainedclay,159,6 +piclay,159,6 +pisclay,159,6 +pistainedclay,159,6 +darkgrayclay,159,7 +darkgraysclay,159,7 +darkgraystainedclay,159,7 +dgrayclay,159,7 +dgraysclay,159,7 +dgraystainedclay,159,7 +darkgreyclay,159,7 +darkgreeysclay,159,7 +darkgreystainedclay,159,7 +dgreyclay,159,7 +dgreysclay,159,7 +dgreystainedclay,159,7 +darkgraclay,159,7 +darkgrasclay,159,7 +darkgrastainedclay,159,7 +dgraclay,159,7 +dgrasclay,159,7 +dgrastainedclay,159,7 +grayclay,159,7 +graysclay,159,7 +graystainedclay,159,7 +greyclay,159,7 +greysclay,159,7 +greystainedclay,159,7 +graclay,159,7 +grasclay,159,7 +grastainedclay,159,7 +lightgrayclay,159,8 +lightgraysclay,159,8 +lightgraystainedclay,159,8 +lgrayclay,159,8 +lgraysclay,159,8 +lgraystainedclay,159,8 +lightgreyclay,159,8 +lightgreysclay,159,8 +lightgreystainedclay,159,8 +lgreyclay,159,8 +lgreysclay,159,8 +lgreystainedclay,159,8 +lightgraclay,159,8 +lightgrasclay,159,8 +lightgrastainedclay,159,8 +lgraclay,159,8 +lgrasclay,159,8 +lgrastainedclay,159,8 +silverclay,159,8 +silversclay,159,8 +silverstainedclay,159,8 +siclay,159,8 +siasclay,159,8 +siastainedclay,159,8 +cyanclay,159,9 +cyansclay,159,9 +cyanstainedclay,159,9 +cclay,159,9 +csclay,159,9 +cstainedclay,159,9 +purpleclay,159,10 +purplesclay,159,10 +purplestainedclay,159,10 +puclay,159,10 +pusclay,159,10 +pustainedclay,159,10 +blueclay,159,11 +bluesclay,159,11 +bluestainedclay,159,11 +bluclay,159,11 +blusclay,159,11 +blustainedclay,159,11 +brownclay,159,12 +brownsclay,159,12 +brownstainedclay,159,12 +broclay,159,12 +brosclay,159,12 +brostainedclay,159,12 +darkgreenclay,159,13 +darkgreensclay,159,13 +darkgreenstainedclay,159,13 +dgreenclay,159,13 +dgreensclay,159,13 +dgreenstainedclay,159,13 +greenclay,159,13 +greensclay,159,13 +greenstainedclay,159,13 +darkgreclay,159,13 +darkgresclay,159,13 +darkgrestainedclay,159,13 +dgreclay,159,13 +dgresclay,159,13 +dgrestainedclay,159,13 +greclay,159,13 +gresclay,159,13 +grestainedclay,159,13 +redclay,159,14 +redsclay,159,14 +redstainedclay,159,14 +rclay,159,14 +rsclay,159,14 +rstainedclay,159,14 +blackclay,159,15 +blacksclay,159,15 +blackstainedclay,159,15 +blaclay,159,15 +blasclay,159,15 +blastainedclay,159,15 +whiteglasspane,160,0 +whitesglasspane,160,0 +whitestainedglasspane,160,0 +wglasspane,160,0 +wsglasspane,160,0 +wstainedglasspane,160,0 +sglasspane,160,0 +stainedglasspane,160,0 +orangeglasspane,160,1 +orangesglasspane,160,1 +orangestainedglasspane,160,1 +oglasspane,160,1 +osglasspane,160,1 +ostainedglasspane,160,1 +magentaglasspane,160,2 +magentasglasspane,160,2 +magentastainedglasspane,160,2 +mglasspane,160,2 +msglasspane,160,2 +mstainedglasspane,160,2 +lightblueglasspane,160,3 +lightbluesglasspane,160,3 +lightbluestainedglasspane,160,3 +lblueglasspane,160,3 +lbluesglasspane,160,3 +lbluestainedglasspane,160,3 +lightbluglasspane,160,3 +lightblusglasspane,160,3 +lightblustainedglasspane,160,3 +lbluglasspane,160,3 +lblusglasspane,160,3 +lblustainedglasspane,160,3 +lbglasspane,160,3 +lbsglasspane,160,3 +lbstainedglasspane,160,3 +yellowglasspane,160,4 +yellowsglasspane,160,4 +yellowstainedglasspane,160,4 +yglasspane,160,4 +ysglasspane,160,4 +ystainedglasspane,160,4 +lightgreenglasspane,160,5 +lightgreensglasspane,160,5 +lightgreenstainedglasspane,160,5 +lgreenglasspane,160,5 +lgreensglasspane,160,5 +lgreenstainedglasspane,160,5 +lightgreglasspane,160,5 +lightgresglasspane,160,5 +lightgrestainedglasspane,160,5 +lgreglasspane,160,5 +lgresglasspane,160,5 +lgrestainedglasspane,160,5 +limeglasspane,160,5 +limesglasspane,160,5 +limestainedglasspane,160,5 +lglasspane,160,5 +lsglasspane,160,5 +lstainedglasspane,160,5 +pinkglasspane,160,6 +pinksglasspane,160,6 +pinkstainedglasspane,160,6 +piglasspane,160,6 +pisglasspane,160,6 +pistainedglasspane,160,6 +darkgrayglasspane,160,7 +darkgraysglasspane,160,7 +darkgraystainedglasspane,160,7 +dgrayglasspane,160,7 +dgraysglasspane,160,7 +dgraystainedglasspane,160,7 +darkgreyglasspane,160,7 +darkgreysglasspane,160,7 +darkgreystainedglasspane,160,7 +dgreyglasspane,160,7 +dgreysglasspane,160,7 +dgreystainedglasspane,160,7 +darkgraglasspane,160,7 +darkgrasglasspane,160,7 +darkgrastainedglasspane,160,7 +dgraglasspane,160,7 +dgrasglasspane,160,7 +dgrastainedglasspane,160,7 +grayglasspane,160,7 +graysglasspane,160,7 +graystainedglasspane,160,7 +greyglasspane,160,7 +greysglasspane,160,7 +greystainedglasspane,160,7 +graglasspane,160,7 +grasglasspane,160,7 +grastainedglasspane,160,7 +lightgrayglasspane,160,8 +lightgraysglasspane,160,8 +lightgraystainedglasspane,160,8 +lgrayglasspane,160,8 +lgraysglasspane,160,8 +lgraystainedglasspane,160,8 +lightgreyglasspane,160,8 +lightgreysglasspane,160,8 +lightgreystainedglasspane,160,8 +lgreyglasspane,160,8 +lgreysglasspane,160,8 +lgreystainedglasspane,160,8 +lightgraglasspane,160,8 +lightgrasglasspane,160,8 +lightgrastainedglasspane,160,8 +lgraglasspane,160,8 +lgrasglasspane,160,8 +lgrastainedglasspane,160,8 +silverglasspane,160,8 +silversglasspane,160,8 +silverstainedglasspane,160,8 +siglasspane,160,8 +siasglasspane,160,8 +siastainedglasspane,160,8 +cyanglasspane,160,9 +cyansglasspane,160,9 +cyanstainedglasspane,160,9 +cglasspane,160,9 +csglasspane,160,9 +cstainedglasspane,160,9 +purpleglasspane,160,10 +purplesglasspane,160,10 +purplestainedglasspane,160,10 +puglasspane,160,10 +pusglasspane,160,10 +pustainedglasspane,160,10 +blueglasspane,160,11 +bluesglasspane,160,11 +bluestainedglasspane,160,11 +bluglasspane,160,11 +blusglasspane,160,11 +blustainedglasspane,160,11 +brownglasspane,160,12 +brownsglasspane,160,12 +brownstainedglasspane,160,12 +broglasspane,160,12 +brosglasspane,160,12 +brostainedglasspane,160,12 +darkgreenglasspane,160,13 +darkgreensglasspane,160,13 +darkgreenstainedglasspane,160,13 +dgreenglasspane,160,13 +dgreensglasspane,160,13 +dgreenstainedglasspane,160,13 +greenglasspane,160,13 +greensglasspane,160,13 +greenstainedglasspane,160,13 +darkgreglasspane,160,13 +darkgresglasspane,160,13 +darkgrestainedglasspane,160,13 +dgreglasspane,160,13 +dgresglasspane,160,13 +dgrestainedglasspane,160,13 +greglasspane,160,13 +gresglasspane,160,13 +grestainedglasspane,160,13 +redglasspane,160,14 +redsglasspane,160,14 +redstainedglasspane,160,14 +rglasspane,160,14 +rsglasspane,160,14 +rstainedglasspane,160,14 +blackglasspane,160,15 +blacksglasspane,160,15 +blackstainedglasspane,160,15 +blaglasspane,160,15 +blasglasspane,160,15 +blastainedglasspane,160,15 +acacialeaves,161,0 +acaciatreeleaves,161,0 +acacialogleaves,161,0 +acaciatrunkleaves,161,0 +acaciawoodleaves,161,0 +aleaves,161,0 +atreeleaves,161,0 +alogleaves,161,0 +atrunkleaves,161,0 +awoodleaves,161,0 +acacialeave,161,0 +acaciatreeleave,161,0 +acacialogleave,161,0 +acaciatrunkleave,161,0 +acaciawoodleave,161,0 +aleave,161,0 +atreeleave,161,0 +alogleave,161,0 +atrunkleave,161,0 +awoodleave,161,0 +acaciatreeleaf,161,0 +acacialogleaf,161,0 +acaciatrunkleaf,161,0 +acaciawoodleaf,161,0 +aleaf,161,0 +atreeleaf,161,0 +alogleaf,161,0 +atrunkleaf,161,0 +awoodleaf,161,0 +darkoakleaves,161,1 +darkoaktreeleaves,161,1 +darkoaklogleaves,161,1 +darkoaktrunkleaves,161,1 +darkoakwoodleaves,161,1 +doakleaves,161,1 +doaktreeleaves,161,1 +doaklogleaves,161,1 +doaktrunkleaves,161,1 +doakwoodleaves,161,1 +doleaves,161,1 +dotreeleaves,161,1 +dologleaves,161,1 +dotrunkleaves,161,1 +dowoodleaves,161,1 +darkoakleave,161,1 +darkoaktreeleave,161,1 +darkoaklogleave,161,1 +darkoaktrunkleave,161,1 +darkoakwoodleave,161,1 +doakleave,161,1 +doaktreeleave,161,1 +doaklogleave,161,1 +doaktrunkleave,161,1 +doakwoodleave,161,1 +doleave,161,1 +dotreeleave,161,1 +dologleave,161,1 +dotrunkleave,161,1 +dowoodleave,161,1 +darkoaktreeleaf,161,1 +darkoaklogleaf,161,1 +darkoaktrunkleaf,161,1 +darkoakwoodleaf,161,1 +doakleaf,161,1 +doaktreeleaf,161,1 +doaklogleaf,161,1 +doaktrunkleaf,161,1 +doakwoodleaf,161,1 +doleaf,161,1 +dotreeleaf,161,1 +dologleaf,161,1 +dotrunkleaf,161,1 +dowoodleaf,161,1 +acacia,162,0 +acaciatree,162,0 +acacialog,162,0 +acaciatrunk,162,0 +acaciawood,162,0 +atree,162,0 +alog,162,0 +atrunk,162,0 +awood,162,0 +darkoak,162,1 +darkoaktree,162,1 +darkoaklog,162,1 +darkoaktrunk,162,1 +darkoakwood,162,1 +doak,162,1 +doaktree,162,1 +doaklog,162,1 +doaktrunk,162,1 +doakwood,162,1 +dotree,162,1 +dolog,162,1 +dotrunk,162,1 +dowood,162,1 +acaciawoodenstairs,163,0 +acaciawoodstairs,163,0 +acaciawstairs,163,0 +acaciastairs,163,0 +awoodenstairs,163,0 +awoodstairs,163,0 +awstairs,163,0 +astairs,163,0 +acaciawoodenstair,163,0 +acaciawoodstair,163,0 +acaciawstair,163,0 +acaciastair,163,0 +awoodenstair,163,0 +awoodstair,163,0 +awstair,163,0 +astair,163,0 +darkoakwoodenstairs,164,0 +darkoakwoodstairs,164,0 +darkoakwstairs,164,0 +darkoakstairs,164,0 +doakwoodenstairs,164,0 +doakwoodstairs,164,0 +doakwstairs,164,0 +doakstairs,164,0 +dowoodenstairs,164,0 +dowoodstairs,164,0 +dowstairs,164,0 +dostairs,164,0 +darkoakwoodenstair,164,0 +darkoakwoodstair,164,0 +darkoakwstair,164,0 +darkoakstair,164,0 +doakwoodenstair,164,0 +doakwoodstair,164,0 +doakwstair,164,0 +doakstair,164,0 +dowoodenstair,164,0 +dowoodstair,164,0 +dowstair,164,0 +dostair,164,0 +hay,170,0 +hayblock,170,0 +haybale,170,0 +baleofhay,170,0 +hayofbale,170,0 +whitecarpet,171,0 +whitefloor,171,0 +wcarpet,171,0 +wfloor,171,0 +carpet,171,0 +floor,171,0 +orangecarpet,171,1 +orangefloor,171,1 +ocarpet,171,1 +ofloor,171,1 +magentacarpet,171,2 +magentafloor,171,2 +mcarpet,171,2 +mfloor,171,2 +lightbluecarpet,171,3 +lightbluefloor,171,3 +lbluecarpet,171,3 +lbluefloor,171,3 +lbcarpet,171,3 +lbfloor,171,3 +lightblucarpet,171,3 +lightblufloor,171,3 +lblucarpet,171,3 +lblufloor,171,3 +yellowcarpet,171,4 +yellowfloor,171,4 +ycarpet,171,4 +yfloor,171,4 +lightgreencarpet,171,5 +lightgreenfloor,171,5 +lgreencarpet,171,5 +lgreenfloor,171,5 +lightgrecarpet,171,5 +lightgrefloor,171,5 +lgrecarpet,171,5 +lgrefloor,171,5 +limecarpet,171,5 +limefloor,171,5 +lcarpet,171,5 +lfloor,171,5 +pinkcarpet,171,6 +pinkfloor,171,6 +picarpet,171,6 +pifloor,171,6 +darkgraycarpet,171,7 +darkgrayfloor,171,7 +dgraycarpet,171,7 +dgrayfloor,171,7 +darkgreycarpet,171,7 +darkgreyfloor,171,7 +dgreycarpet,171,7 +dgreyfloor,171,7 +darkgracarpet,171,7 +darkgrafloor,171,7 +dgracarpet,171,7 +dgrafloor,171,7 +graycarpet,171,7 +grayfloor,171,7 +greycarpet,171,7 +greyfloor,171,7 +gracarpet,171,7 +grafloor,171,7 +lightgraycarpet,171,8 +lightgrayfloor,171,8 +lgraycarpet,171,8 +lgrayfloor,171,8 +lightgreycarpet,171,8 +lightgreyfloor,171,8 +lgreycarpet,171,8 +lgreyfloor,171,8 +lightgracarpet,171,8 +lightgrafloor,171,8 +lgracarpet,171,8 +lgrafloor,171,8 +silvercarpet,171,8 +silverfloor,171,8 +sicarpet,171,8 +siafloor,171,8 +cyancarpet,171,9 +cyanfloor,171,9 +ccarpet,171,9 +cfloor,171,9 +purplecarpet,171,10 +purplefloor,171,10 +pucarpet,171,10 +pufloor,171,10 +bluecarpet,171,11 +bluefloor,171,11 +blucarpet,171,11 +blufloor,171,11 +browncarpet,171,12 +brownfloor,171,12 +brocarpet,171,12 +brofloor,171,12 +darkgreencarpet,171,13 +darkgreenfloor,171,13 +dgreencarpet,171,13 +dgreenfloor,171,13 +greencarpet,171,13 +greenfloor,171,13 +darkgrecarpet,171,13 +darkgrefloor,171,13 +dgrecarpet,171,13 +dgrefloor,171,13 +grecarpet,171,13 +grefloor,171,13 +redcarpet,171,14 +redfloor,171,14 +rcarpet,171,14 +rfloor,171,14 +blackcarpet,171,15 +blackfloor,171,15 +blacarpet,171,15 +blafloor,171,15 +hardenedclay,172,0 +hardclay,172,0 +hclay,172,0 +coalblock,173,0 +blockcoal,173,0 +coblock,173,0 +blockco,173,0 +coalb,173,0 +bcoal,173,0 +packedice,174,0 +packice,174,0 +solidice,174,0 +sunflower,175,0 +yellowsunflower,175,0 +lilac,175,1 +magentalilac,175,1 +syringa,175,1 +longtallgrass,175,2 +extratallgrass,175,2 +doubletallgrass,175,2 +largetallgrass,175,2 +longtgrass,175,2 +extratgrass,175,2 +doubletgrass,175,2 +largetgrass,175,2 +ltgrass,175,2 +etgrass,175,2 +dtgrass,175,2 +bigfern,175,3 +largefern,175,3 +doublefern,175,3 +bfern,175,3 +lfern,175,3 +dfern,175,3 +rosebush,175,4 +redrosebush,175,4 +peony,175,5 +pinkpeony,175,5 +paeonia,175,5 +ironshovel,256,0 +ironspade,256,0 +ishovel,256,0 +ispade,256,0 +steelshovel,256,0 +steelspade,256,0 +ironpickaxe,257,0 +ironpick,257,0 +steelpickaxe,257,0 +steelpick,257,0 +ipickaxe,257,0 +ipick,257,0 +ironaxe,258,0 +iaxe,258,0 +steelaxe,258,0 +flintandsteel,259,0 +flintandiron,259,0 +flintandtinder,259,0 +flintnsteel,259,0 +flintniron,259,0 +flintntinder,259,0 +flintsteel,259,0 +flintiron,259,0 +flinttinder,259,0 +lighter,259,0 +apple,260,0 +normalapple,260,0 +redapple,260,0 +bow,261,0 +arrow,262,0 +coal,263,0 +charcoal,263,1 +ccoal,263,1 +diamond,264,0 +crystal,264,0 +ironingot,265,0 +ironbar,265,0 +ironi,265,0 +steelingot,265,0 +steelbar,265,0 +steeli,265,0 +iingot,265,0 +ibar,265,0 +ingotiron,265,0 +bariron,265,0 +iiron,265,0 +ingotsteel,265,0 +barsteel,265,0 +isteel,265,0 +ingoti,265,0 +bari,265,0 +goldingot,266,0 +goldbar,266,0 +goldi,266,0 +gingot,266,0 +gbar,266,0 +ingotgold,266,0 +bargold,266,0 +igold,266,0 +ingotg,266,0 +barg,266,0 +ironsword,267,0 +steelsword,267,0 +isword,267,0 +woodensword,268,0 +woodsword,268,0 +wsword,268,0 +woodenshovel,269,0 +woodenspade,269,0 +woodshovel,269,0 +woodspade,269,0 +wshovel,269,0 +wspade,269,0 +woodenpickaxe,270,0 +woodenpick,270,0 +woodpickaxe,270,0 +woodpick,270,0 +wpickaxe,270,0 +wpick,270,0 +woodenaxe,271,0 +woodaxe,271,0 +waxe,271,0 +stonesword,272,0 +cobblestonesword,272,0 +cstonesword,272,0 +cssword,272,0 +ssword,272,0 +stoneshovel,273,0 +cobblestoneshovel,273,0 +cobblestonespade,273,0 +cstoneshovel,273,0 +cstonespade,273,0 +stonespade,273,0 +csshovel,273,0 +csspade,273,0 +sshovel,273,0 +sspade,273,0 +stonepickaxe,274,0 +cobblestonepickaxe,274,0 +cobblestonepick,274,0 +cstonepickaxe,274,0 +cstonepick,274,0 +stonepick,274,0 +cspickaxe,274,0 +cspick,274,0 +spickaxe,274,0 +spick,274,0 +stoneaxe,275,0 +cobblestoneaxe,275,0 +cstoneaxe,275,0 +csaxe,275,0 +saxe,275,0 +diamondsword,276,0 +crystalsword,276,0 +dsword,276,0 +diamondshovel,277,0 +diamondspade,277,0 +crystalshovel,277,0 +crystalspade,277,0 +dshovel,277,0 +dspade,277,0 +diamondpickaxe,278,0 +diamondpick,278,0 +crystalpickaxe,278,0 +crystalpick,278,0 +dpickaxe,278,0 +dpick,278,0 +diamondaxe,279,0 +crystalaxe,279,0 +daxe,279,0 +stick,280,0 +twig,280,0 +branch,280,0 +bowl,281,0 +woodenbowl,281,0 +woodbowl,281,0 +mushroomsoup,282,0 +mrsoup,282,0 +soup,282,0 +goldsword,283,0 +gsword,283,0 +goldshovel,284,0 +goldspade,284,0 +gshovel,284,0 +gspade,284,0 +goldpickaxe,285,0 +goldpick,285,0 +gpickaxe,285,0 +gpick,285,0 +goldaxe,286,0 +gaxe,286,0 +string,287,0 +thread,287,0 +feather,288,0 +gunpowder,289,0 +sulfur,289,0 +woodenhoe,290,0 +woodhoe,290,0 +whoe,290,0 +stonehoe,291,0 +cobblestonehoe,291,0 +cstonehoe,291,0 +cshoe,291,0 +shoe,291,0 +ironhoe,292,0 +steelhoe,292,0 +ihoe,292,0 +diamondhoe,293,0 +crystalhoe,293,0 +dhoe,293,0 +goldhoe,294,0 +ghoe,294,0 +seeds,295,0 +seed,295,0 +wheat,296,0 +crops,296,0 +crop,296,0 +bread,297,0 +leatherhelmet,298,0 +leatherhelm,298,0 +leatherhat,298,0 +leathercoif,298,0 +lhelmet,298,0 +lhelm,298,0 +lhat,298,0 +lcoif,298,0 +leatherchestplate,299,0 +leatherplatebody,299,0 +leatherplate,299,0 +leathershirt,299,0 +leathertunic,299,0 +lchestplate,299,0 +lplatebody,299,0 +lplate,299,0 +lshirt,299,0 +ltunic,299,0 +leatherleggings,300,0 +leatherlegs,300,0 +leatherpants,300,0 +lleggings,300,0 +llegs,300,0 +lpants,300,0 +leatherboots,301,0 +leathershoes,301,0 +lboots,301,0 +lshoes,301,0 +chainmailhelmet,302,0 +chainmailhelm,302,0 +chainmailhat,302,0 +chainmailcoif,302,0 +chainmhelmet,302,0 +chainmhelm,302,0 +chainmhat,302,0 +chainmcoif,302,0 +cmailhelmet,302,0 +cmailhelm,302,0 +cmailhat,302,0 +cmailcoif,302,0 +chainhelmet,302,0 +chainhelm,302,0 +chainhat,302,0 +chaincoif,302,0 +cmhelmet,302,0 +cmhelm,302,0 +cmhat,302,0 +cmcoif,302,0 +chainmailchestplate,303,0 +chainmailplatebody,303,0 +chainmailplate,303,0 +chainmailshirt,303,0 +chainmailtunic,303,0 +chainmchestplate,303,0 +chainmplatebody,303,0 +chainmplate,303,0 +chainmshirt,303,0 +chainmtunic,303,0 +cmailchestplate,303,0 +cmailplatebody,303,0 +cmailplate,303,0 +cmailshirt,303,0 +cmailtunic,303,0 +chainchestplate,303,0 +chainplatebody,303,0 +chainplate,303,0 +chainshirt,303,0 +chaintunic,303,0 +cmchestplate,303,0 +cmplatebody,303,0 +cmplate,303,0 +cmshirt,303,0 +cmtunic,303,0 +chainmailleggings,304,0 +chainmaillegs,304,0 +chainmailpants,304,0 +chainmleggings,304,0 +chainmlegs,304,0 +chainmpants,304,0 +cmailleggings,304,0 +cmaillegs,304,0 +cmailpants,304,0 +chainleggings,304,0 +chainlegs,304,0 +chainpants,304,0 +cmleggings,304,0 +cmlegs,304,0 +cmpants,304,0 +chainmailboots,305,0 +chainmailshoes,305,0 +chainmboots,305,0 +chainmshoes,305,0 +cmailboots,305,0 +cmailshoes,305,0 +chainboots,305,0 +chainshoes,305,0 +cmboots,305,0 +cmshoes,305,0 +ironhelmet,306,0 +ironhelm,306,0 +ironhat,306,0 +ironcoif,306,0 +ihelmet,306,0 +ihelm,306,0 +ihat,306,0 +icoif,306,0 +steelhelmet,306,0 +steelhelm,306,0 +steelhat,306,0 +steelcoif,306,0 +shelmet,306,0 +shelm,306,0 +shat,306,0 +scoif,306,0 +ironchestplate,307,0 +ironplatebody,307,0 +ironshirt,307,0 +irontunic,307,0 +ichestplate,307,0 +iplatebody,307,0 +ishirt,307,0 +itunic,307,0 +steelchestplate,307,0 +steelplatebody,307,0 +steelplate,307,0 +steelshirt,307,0 +steeltunic,307,0 +schestplate,307,0 +splatebody,307,0 +sshirt,307,0 +stunic,307,0 +ironleggings,308,0 +ironlegs,308,0 +ironpants,308,0 +ileggings,308,0 +ilegs,308,0 +ipants,308,0 +steelleggings,308,0 +steellegs,308,0 +steelpants,308,0 +sleggings,308,0 +slegs,308,0 +spants,308,0 +ironboots,309,0 +ironshoes,309,0 +iboots,309,0 +ishoes,309,0 +steelboots,309,0 +steelshoes,309,0 +sboots,309,0 +sshoes,309,0 +diamondhelmet,310,0 +diamondhelm,310,0 +diamondhat,310,0 +diamondcoif,310,0 +dhelmet,310,0 +dhelm,310,0 +dhat,310,0 +dcoif,310,0 +crystalhelmet,310,0 +crystalhelm,310,0 +crystalhat,310,0 +crystalcoif,310,0 +chelmet,310,0 +chelm,310,0 +chat,310,0 +ccoif,310,0 +diamondchestplate,311,0 +diamondplatebody,311,0 +diamondplate,311,0 +diamondshirt,311,0 +diamondtunic,311,0 +dchestplate,311,0 +dplatebody,311,0 +dplate,311,0 +dshirt,311,0 +dtunic,311,0 +crystalchestplate,311,0 +crystalplatebody,311,0 +crystalplate,311,0 +crystalshirt,311,0 +crystaltunic,311,0 +cchestplate,311,0 +cplatebody,311,0 +cplate,311,0 +cshirt,311,0 +ctunic,311,0 +diamondleggings,312,0 +diamondlegs,312,0 +diamondpants,312,0 +dleggings,312,0 +dlegs,312,0 +dpants,312,0 +crystalleggings,312,0 +crystallegs,312,0 +crystalpants,312,0 +cleggings,312,0 +clegs,312,0 +cpants,312,0 +diamondboots,313,0 +diamondshoes,313,0 +dboots,313,0 +dshoes,313,0 +crystalboots,313,0 +crystalshoes,313,0 +cboots,313,0 +cshoes,313,0 +goldhelmet,314,0 +goldhelm,314,0 +goldhat,314,0 +goldcoif,314,0 +ghelmet,314,0 +ghelm,314,0 +ghat,314,0 +gcoif,314,0 +goldchestplate,315,0 +goldplatebody,315,0 +goldshirt,315,0 +goldtunic,315,0 +gchestplate,315,0 +gplatebody,315,0 +gplateplate,315,0 +gshirt,315,0 +gtunic,315,0 +goldleggings,316,0 +goldlegs,316,0 +goldpants,316,0 +gleggings,316,0 +glegs,316,0 +gpants,316,0 +goldboots,317,0 +goldshoes,317,0 +gboots,317,0 +gshoes,317,0 +flint,318,0 +pork,319,0 +porkchop,319,0 +rawpork,319,0 +rpork,319,0 +rawporkchop,319,0 +rporkchop,319,0 +cookedpork,320,0 +grilledpork,320,0 +grillpork,320,0 +gpork,320,0 +cookpork,320,0 +cpork,320,0 +grilledporkchop,320,0 +grillporkchop,320,0 +gporkchop,320,0 +cookedporkchop,320,0 +cookporkchop,320,0 +cporkchop,320,0 +bacon,320,0 +painting,321,0 +picture,321,0 +goldenapple,322,0 +goldapple,322,0 +gapple,322,0 +enchantedgoldenapple,322,1 +enchantedgoldapple,322,1 +enchantedgapple,322,1 +supergoldenapple,322,1 +supergoldapple,322,1 +supergapple,322,1 +magicalgoldenapple,322,1 +magicalgoldapple,322,1 +magicalgapple,322,1 +magicgoldenapple,322,1 +magicgoldapple,322,1 +magicgapple,322,1 +egoldenapple,322,1 +egoldapple,322,1 +egapple,322,1 +sgoldenapple,322,1 +sgoldapple,322,1 +sgapple,322,1 +mgoldenapple,322,1 +mgoldapple,322,1 +mgapple,322,1 +sign,323,0 +woodendoor,324,0 +wooddoor,324,0 +wdoor,324,0 +door,324,0 +bucket,325,0 +bukkit,325,0 +waterbucket,326,0 +waterbukkit,326,0 +wbucket,326,0 +wbukkit,326,0 +magmabucket,327,0 +magmabukkit,327,0 +lavabucket,327,0 +lavabukkit,327,0 +lbucket,327,0 +lbukkit,327,0 +minecart,328,0 +mcart,328,0 +cart,328,0 +saddle,329,0 +irondoor,330,0 +idoor,330,0 +steeldoor,330,0 +sdoor,330,0 +dooriron,330,0 +doori,330,0 +doorsteel,330,0 +doors,330,0 +redstonedust,331,0 +redstone,331,0 +rstonedust,331,0 +rstone,331,0 +redsdust,331,0 +reddust,331,0 +rsdust,331,0 +rdust,331,0 +snow,332,0 +snowball,332,0 +snball,332,0 +sball,332,0 +boat,333,0 +leather,334,0 +cowhide,334,0 +hide,334,0 +milkbucket,335,0 +milkbukkit,335,0 +mbucket,335,0 +mbukkit,335,0 +claybrick,336,0 +brick,336,0 +redbrick,336,0 +rbrick,336,0 +clayball,337,0 +cball,337,0 +clay,337,0 +reeds,338,0 +reed,338,0 +sugarcane,338,0 +scane,338,0 +bamboo,338,0 +paper,339,0 +papyrus,339,0 +book,340,0 +slimeball,341,0 +slball,341,0 +chestminecart,342,0 +storageminecart,342,0 +storagemcart,342,0 +chestmcart,342,0 +storagecart,342,0 +chestcart,342,0 +sminecart,342,0 +cminecart,342,0 +smcart,342,0 +cmcart,342,0 +scart,342,0 +ccart,342,0 +furnaceminecart,343,0 +engineminecart,343,0 +poweredminecart,343,0 +powerminecart,343,0 +enginemcart,343,0 +poweredmcart,343,0 +powermcart,343,0 +furnacemcart,343,0 +enginecart,343,0 +poweredcart,343,0 +powercart,343,0 +furnacecart,343,0 +eminecart,343,0 +pminecart,343,0 +fminecart,343,0 +emcart,343,0 +pmcart,343,0 +fmcart,343,0 +ecart,343,0 +pcart,343,0 +fcart,343,0 +egg,344,0 +compass,345,0 +fishingrod,346,0 +fishrod,346,0 +frod,346,0 +rod,346,0 +watch,347,0 +goldwatch,347,0 +goldclock,347,0 +gwatch,347,0 +gclock,347,0 +clock,347,0 +glowstonedust,348,0 +glowingstonedust,348,0 +lightstonedust,348,0 +lbdust,348,0 +gbdust,348,0 +lsdust,348,0 +gsdust,348,0 +rawfish,349,0 +rafish,349,0 +fish,349,0 +rawsalmonfish,349,1 +rasalmonfish,349,1 +salmonfish,349,1 +rawsalmon,349,1 +rasalmon,349,1 +salmon,349,1 +sfish,349,1 +fishs,349,1 +rawclownfish,349,2 +raclownfish,349,2 +clownfish,349,2 +rawnemo,349,2 +ranemo,349,2 +nemo,349,2 +nemofish,349,2 +fishnemo,349,2 +clfish,349,2 +fishcl,349,2 +nfish,349,2 +fishn,349,2 +rawpufferfish,349,3 +rapufferfish,349,3 +pufferfish,349,3 +pufffish,349,3 +fishpuff,349,3 +pfish,349,3 +fishp,349,3 +cookedfish,350,0 +cookfish,350,0 +cfish,350,0 +grilledfish,350,0 +grillfish,350,0 +gfish,350,0 +roastedfish,350,0 +roastfish,350,0 +rofish,350,0 +cookedsalmonfish,350,1 +cooksalmonfish,350,1 +csalmonfish,350,1 +grilledsalmonfish,350,1 +grillsalmonfish,350,1 +gsalmonfish,350,1 +roastedsalmonfish,350,1 +roastsalmonfish,350,1 +rosalmonfish,350,1 +cookedsalmon,350,1 +cooksalmon,350,1 +csalmon,350,1 +grilledsalmon,350,1 +grillsalmon,350,1 +gsalmon,350,1 +roastedsalmon,350,1 +roastsalmon,350,1 +rosalmon,350,1 +dye,351,0 +inksack,351,0 +inksac,351,0 +isack,351,0 +isac,351,0 +sack,351,0 +sac,351,0 +blackinksack,351,0 +blackinksac,351,0 +blackisack,351,0 +blackisac,351,0 +blacksack,351,0 +blacksac,351,0 +inksackblack,351,0 +inksacblack,351,0 +isackblack,351,0 +isacblack,351,0 +sackblack,351,0 +sacblack,351,0 +blackinksackcolour,351,0 +blackinksaccolour,351,0 +blackisackcolour,351,0 +blackisaccolour,351,0 +blacksackcolour,351,0 +blacksaccolour,351,0 +inksackblackcolour,351,0 +inksacblackcolour,351,0 +isackblackcolour,351,0 +isacclackcolour,351,0 +sackblackcolour,351,0 +sacblackcolour,351,0 +blackinksackcolor,351,0 +blackinksaccolor,351,0 +blackisackcolor,351,0 +blackisaccolor,351,0 +blacksackcolor,351,0 +blacksaccolor,351,0 +inksackblackcolor,351,0 +inksacblackcolor,351,0 +isackblackcolor,351,0 +isacblackcolor,351,0 +sackblackcolor,351,0 +sacblackcolor,351,0 +blackinksackdye,351,0 +blackinksacdye,351,0 +blackisackdye,351,0 +blackisacdye,351,0 +blacksackdye,351,0 +blacksacdye,351,0 +inksackblackdye,351,0 +inksacblackdye,351,0 +isackblackdye,351,0 +isacclackdye,351,0 +sackblackdye,351,0 +sacblackdye,351,0 +blackcolor,351,0 +blackdye,351,0 +rosered,351,1 +roseredcolor,351,1 +roseredcolour,351,1 +rosereddye,351,1 +redrosecolor,351,1 +redrosecolour,351,1 +redrosedye,351,1 +redr,351,1 +redrcolor,351,1 +redrcolour,351,1 +redrdye,351,1 +redcolor,351,1 +redcolour,351,1 +reddye,351,1 +cactusgreen,351,2 +greencactus,351,2 +cactusgreencolour,351,2 +greencactuscolour,351,2 +cactusgreencolor,351,2 +greencactuscolor,351,2 +cactusgreendye,351,2 +greencactusdye,351,2 +greencolour,351,2 +greencolor,351,2 +greendye,351,2 +cocoabeans,351,3 +cocoabean,351,3 +cocobeans,351,3 +cocobean,351,3 +cbeans,351,3 +cbean,351,3 +beans,351,3 +bean,351,3 +browncocoabeans,351,3 +browncocoabean,351,3 +browncocobeans,351,3 +browncocobean,351,3 +browncbeans,351,3 +browncbean,351,3 +brownbeans,351,3 +brownbean,351,3 +brownb,351,3 +cocoabeanscolour,351,3 +cocoabeancolour,351,3 +cocobeanscolour,351,3 +cocobeancolour,351,3 +cbeanscolour,351,3 +cbeancolour,351,3 +beanscolour,351,3 +beancolour,351,3 +browncocoabeanscolour,351,3 +browncocoabeancolour,351,3 +browncocobeanscolour,351,3 +browncocobeancolour,351,3 +browncbeanscolour,351,3 +browncbeancolour,351,3 +brownbeanscolour,351,3 +brownbeancolour,351,3 +brownbcolour,351,3 +cocoabeanscolor,351,3 +cocoabeancolor,351,3 +cocobeanscolor,351,3 +cocobeancolor,351,3 +cbeanscolor,351,3 +cbeancolor,351,3 +beanscolor,351,3 +beancolor,351,3 +browncocoabeanscolor,351,3 +browncocoabeancolor,351,3 +browncocobeanscolor,351,3 +browncocobeancolor,351,3 +browncbeanscolor,351,3 +browncbeancolor,351,3 +brownbeanscolor,351,3 +brownbeancolor,351,3 +brownbcolor,351,3 +cocoabeansdye,351,3 +cocoabeandye,351,3 +cocobeansdye,351,3 +cocobeandye,351,3 +cbeansdye,351,3 +cbeandye,351,3 +beansdye,351,3 +beandye,351,3 +browncocoabeansdye,351,3 +browncocoabeandye,351,3 +browncocobeansdye,351,3 +browncocobeandye,351,3 +browncbeansdye,351,3 +browncbeandye,351,3 +brownbeansdye,351,3 +brownbeandye,351,3 +brownbdye,351,3 +browncolour,351,3 +browncolor,351,3 +browndye,351,3 +lapislazuli,351,4 +bluelapislazuli,351,4 +bluelapisl,351,4 +bluelapis,351,4 +bluel,351,4 +lapislazuliblue,351,4 +lapislblue,351,4 +lapisblue,351,4 +lapisl,351,4 +lapis,351,4 +bluelapislazulicolour,351,4 +bluelapislcolour,351,4 +bluelapiscolour,351,4 +lapislazulibluecolour,351,4 +lapislbluecolour,351,4 +lapisbluecolour,351,4 +lapislazulicolour,351,4 +lapislcolour,351,4 +lapiscolour,351,4 +bluelapislazulicolor,351,4 +bluelapislcolor,351,4 +bluelapiscolor,351,4 +lapislazulibluecolor,351,4 +lapislbluecolor,351,4 +lapisbluecolor,351,4 +lapislazulicolor,351,4 +lapislcolor,351,4 +lapiscolor,351,4 +bluelapislazulidye,351,4 +bluelapisldye,351,4 +bluelapisdye,351,4 +lapislazulibluedye,351,4 +lapislbluedye,351,4 +lapisbluedye,351,4 +lapislazulidye,351,4 +lapisldye,351,4 +lapisdye,351,4 +bluecolour,351,4 +bluecolor,351,4 +bluedye,351,4 +purpledye,351,5 +purplecolour,351,5 +purplecolor,351,5 +cyandye,351,6 +cyancolour,351,6 +cyancolor,351,6 +lightgraydye,351,7 +lightgraycolour,351,7 +lightgraycolor,351,7 +lgraycolour,351,7 +lgraycolor,351,7 +lgraydye,351,7 +lightgreydye,351,7 +lightgreycolour,351,7 +lightgreycolor,351,7 +lgreycolour,351,7 +lgreycolor,351,7 +lgreydye,351,7 +silvercolour,351,7 +silvercolor,351,7 +silverdye,351,7 +darkgraydye,351,8 +darkgraycolour,351,8 +darkgraycolor,351,8 +dgraycolour,351,8 +dgraycolor,351,8 +dgraydye,351,8 +graycolour,351,8 +graycolor,351,8 +graydye,351,8 +darkgreydye,351,8 +darkgreycolour,351,8 +darkgreycolor,351,8 +dgreycolour,351,8 +dgreycolor,351,8 +dgreydye,351,8 +greycolour,351,8 +greycolor,351,8 +greydye,351,8 +pinkdye,351,9 +pinkcolour,351,9 +pinkcolor,351,9 +limedye,351,10 +limecolour,351,10 +limecolor,351,10 +dandelionyellow,351,11 +dandelionyellowcolour,351,11 +dandelionyellowcolor,351,11 +dandelionyellowdye,351,11 +yellowdandelioncolour,351,11 +yellowdandelioncolor,351,11 +yellowdandeliondye,351,11 +yellowd,351,11 +yellowdcolour,351,11 +yellowdcolor,351,11 +yellowddye,351,11 +dyellow,351,11 +dyellowcolour,351,11 +dyellowcolor,351,11 +dyellowdye,351,11 +yellowcolour,351,11 +yellowcolor,351,11 +yellowdye,351,11 +lightbluecolour,351,12 +lightbluecolor,351,12 +lightbluedye,351,12 +lbluecolour,351,12 +lbluecolor,351,12 +lbluedye,351,12 +magentacolour,351,13 +magentacolor,351,13 +magentadye,351,13 +orangecolour,351,14 +orangecolor,351,14 +orangedye,351,14 +bonemeal,351,15 +whitebonemeal,351,15 +whitebonemealcolour,351,15 +whitebonemealcolor,351,15 +whitebonemealdye,351,15 +bonemealwhite,351,15 +bonemealwhitecolour,351,15 +bonemealwhitecolor,351,15 +bonemealwhitedye,351,15 +whitebonem,351,15 +whitebonemcolour,351,15 +whitebonemcolor,351,15 +whitebonemdye,351,15 +bonemwhite,351,15 +bonemwhitecolour,351,15 +bonemwhitecolor,351,15 +bonemwhitedye,351,15 +bonemealcolour,351,15 +bonemealcolor,351,15 +bonemealdye,351,15 +bonem,351,15 +bonemcolour,351,15 +bonemcolor,351,15 +bonemdye,351,15 +whitecolour,351,15 +whitecolor,351,15 +whitedye,351,15 +bone,352,0 +sugar,353,0 +whitedust,353,0 +cake,354,0 +bed,355,0 +redstonerepeater,356,0 +redstonerepeat,356,0 +redstonedelayer,356,0 +redstonedelay,356,0 +redstonedioder,356,0 +redstonediode,356,0 +rstonerepeater,356,0 +rstonerepeat,356,0 +rstonedelayer,356,0 +rstonedelay,356,0 +rstonedioder,356,0 +rstonediode,356,0 +redsrepeater,356,0 +redsrepeat,356,0 +redsdelayer,356,0 +redsdelay,356,0 +redsdioder,356,0 +redsdiode,356,0 +rsrepeater,356,0 +rsrepeat,356,0 +rsdelayer,356,0 +rsdelay,356,0 +rsdioder,356,0 +rsdiode,356,0 +repeater,356,0 +repeat,356,0 +delayer,356,0 +delay,356,0 +dioder,356,0 +diode,356,0 +cookie,357,0 +chart,358,0 +map0,358,0 +map1,358,1 +map2,358,2 +map3,358,3 +map4,358,4 +map5,358,5 +map6,358,6 +map7,358,7 +map8,358,8 +map9,358,9 +map10,358,10 +map11,358,11 +map12,358,12 +map13,358,13 +map14,358,14 +map15,358,15 +shears,359,0 +shear,359,0 +sheers,359,0 +sheer,359,0 +woolcutters,359,0 +woolcutter,359,0 +cutterswool,359,0 +cutterwool,359,0 +melonslice,360,0 +mslice,360,0 +slicemelon,360,0 +watermelonslice,360,0 +greenmelonslice,360,0 +melongreenslice,360,0 +pumpkinseeds,361,0 +pseeds,361,0 +seedsp,361,0 +seedspumpkin,361,0 +pumpseeds,361,0 +seedspump,361,0 +melonseeds,362,0 +mseeds,362,0 +watermelonseeds,362,0 +greenmelonseeds,362,0 +gmelonseeds,362,0 +seedsmelon,362,0 +seedswatermelon,362,0 +rawbeef,363,0 +rawsteak,363,0 +uncookedbeef,363,0 +uncookedsteak,363,0 +cowmeat,363,0 +plainbeef,363,0 +beef,364,0 +steak,364,0 +cookedbeef,364,0 +grilledbeef,364,0 +cookedsteak,364,0 +grilledsteak,364,0 +cookedcowmeat,364,0 +rawchicken,365,0 +uncookedchicken,365,0 +plainchicken,365,0 +chickenplain,365,0 +chickenuncooked,365,0 +chickenraw,365,0 +cookedchicken,366,0 +grilledchicken,366,0 +toastedchicken,366,0 +gchicken,366,0 +bbqchicken,366,0 +friedchicken,366,0 +cchicken,366,0 +rottenflesh,367,0 +zombieflesh,367,0 +rottenmeat,367,0 +zombiemeat,367,0 +badflesh,367,0 +poisonflesh,367,0 +zombieremains,367,0 +enderpearl,368,0 +endpearl,368,0 +pearl,368,0 +epearl,368,0 +bluepearl,368,0 +endergem,368,0 +blazerod,369,0 +goldenrod,369,0 +goldrod,369,0 +blazestick,369,0 +goldstick,369,0 +brod,369,0 +grod,369,0 +bstick,369,0 +gstick,369,0 +ghasttear,370,0 +ghastdrop,370,0 +ghosttear,370,0 +ghostdrop,370,0 +gtear,370,0 +gdrop,370,0 +tear,370,0 +goldnugget,371,0 +gnugget,371,0 +goldpebble,371,0 +gpebble,371,0 +goldball,371,0 +gball,371,0 +netherstalk,372,0 +deathstalk,372,0 +hellstalk,372,0 +nstalk,372,0 +dstalk,372,0 +hstalk,372,0 +netherwarts,372,0 +netherwart,372,0 +netherplant,372,0 +nethercrop,372,0 +hellwarts,372,0 +hellwart,372,0 +hellplant,372,0 +hellcrop,372,0 +deathwarts,372,0 +deathwart,372,0 +deathplant,372,0 +deathcrop,372,0 +nwarts,372,0 +nwart,372,0 +ncrop,372,0 +nplant,372,0 +hwarts,372,0 +hwart,372,0 +hplant,372,0 +hcrop,372,0 +dwarts,372,0 +dwart,372,0 +dplant,372,0 +dcrop,372,0 +potion,373,0 +mixture,373,0 +potions,373,0 +waterbottle,373,0 +fullbottle,373,0 +watervase,373,0 +fullvase,373,0 +clearpotion,373,6 +clearpot,373,6 +clearextendedpotion,373,7 +clearexpotion,373,7 +clear2potion,373,7 +clearextendedpot,373,7 +clearexpot,373,7 +clear2pot,373,7 +diffusepotion,373,11 +diffusepot,373,11 +artlesspotion,373,13 +artlesspot,373,13 +thinpotion,373,14 +thinpot,373,14 +thinextendedpotion,373,15 +thinexpotion,373,15 +thin2potion,373,15 +thinextendedpot,373,15 +thinexpot,373,15 +thin2pot,373,15 +awkwardpotion,373,16 +awkwardpot,373,16 +bunglingpotion,373,22 +bunglingpot,373,22 +bunglingextendedpotion,373,23 +bunglingexpotion,373,23 +bungling2potion,373,23 +bunglingextendedpot,373,23 +bunglingexpot,373,23 +bungling2pot,373,23 +smoothpotion,373,27 +smoothpot,373,27 +suavepotion,373,29 +suavepot,373,29 +debonairpotion,373,30 +debonairpot,373,30 +debonairextendedpotion,373,31 +debonairexpotion,373,31 +debonair2potion,373,31 +debonairextendedpot,373,31 +debonairexpot,373,31 +debonair2pot,373,31 +thickpotion,373,32 +thickpot,373,32 +charmingpotion,373,38 +charmingpot,373,38 +charmingextendedpotion,373,39 +charmingexpotion,373,39 +charming2potion,373,39 +charmingextendedpot,373,39 +charmingexpot,373,39 +charming2pot,373,39 +refinedpotion,373,43 +refinedpot,373,43 +cordialpotion,373,45 +cordialpot,373,45 +sparklingpotion,373,46 +sparklingpot,373,46 +sparklingextendedpotion,373,47 +sparklingexpotion,373,47 +sparkling2potion,373,47 +sparklingextendedpot,373,47 +sparklingexpot,373,47 +sparkling2pot,373,47 +potentpotion,373,48 +potentpot,373,48 +rankpotion,373,54 +rankpot,373,54 +rankextendedpotion,373,55 +rankexpotion,373,55 +rank2potion,373,55 +rankextendedpot,373,55 +rankexpot,373,55 +rank2pot,373,55 +acridpotion,373,59 +acridpot,373,59 +grosspotion,373,61 +grosspot,373,61 +stinkypotion,373,62 +stinkypot,373,62 +stinkyextendedpotion,373,63 +stinkyexpotion,373,63 +stinky2potion,373,63 +stinkyextendedpot,373,63 +stinkyexpot,373,63 +stinky2pot,373,63 +mundaneextendedpotion,373,64 +mundaneexpotion,373,64 +mundane2potion,373,64 +mundaneextendedpot,373,64 +mundaneexpot,373,64 +mundane2pot,373,64 +mundanepotion,373,8192 +mundanepot,373,8192 +regenerationpotion,373,8193 +regeneratepotion,373,8193 +regenpotion,373,8193 +regenerationpot,373,8193 +regeneratepot,373,8193 +regenpot,373,8193 +rpot,373,8193 +swiftnesspotion,373,8194 +swiftpotion,373,8194 +speedpotion,373,8194 +swiftnesspot,373,8194 +swiftpot,373,8194 +speedpot,373,8194 +swpot,373,8194 +fireresistancepotion,373,8195 +fireresistpotion,373,8195 +firerespotion,373,8195 +fireresistancepot,373,8195 +fireresistpot,373,8195 +firerespot,373,8195 +fpot,373,8195 +poisonpotion,373,8196 +acidpotion,373,8196 +poisonpot,373,8196 +acidpot,373,8196 +ppot,373,8196 +healingpotion,373,8197 +healpotion,373,8197 +lifepotion,373,8197 +healingpot,373,8197 +healpot,373,8197 +lifepot,373,8197 +hpot,373,8197 +nightvisionpotion,373,8198 +nvisionpotion,373,8198 +nightvpotion,373,8198 +darkvisionpotion,373,8198 +dvisionpotion,373,8198 +darkvpotion,373,8198 +nightvisionpot,373,8198 +nvisionpot,373,8198 +nightvpot,373,8198 +darkvisionpot,373,8198 +dvisionpot,373,8198 +darkvpot,373,8198 +npot,373,8198 +weaknesspotion,373,8200 +weakpotion,373,8200 +weaknesspot,373,8200 +weakpot,373,8200 +wpot,373,8200 +strengthpotion,373,8201 +strongpotion,373,8201 +strpotion,373,8201 +strengthpot,373,8201 +strongpot,373,8201 +strpot,373,8201 +stpot,373,8201 +slownesspotion,373,8202 +slowpotion,373,8202 +slownesspot,373,8202 +slowpot,373,8202 +slpot,373,8202 +harmingpotion,373,8204 +damagepotion,373,8204 +dmgpotion,373,8204 +harmingpot,373,8204 +damagepot,373,8204 +dmgpot,373,8204 +dpot,373,8204 +waterbreathingpotion,373,8205 +waterbreathpotion,373,8205 +breathingpotion,373,8205 +breathpotion,373,8205 +waterbreathingpot,373,8205 +waterbreathpot,373,8205 +breathingpot,373,8205 +breathpot,373,8205 +wbpot,373,8205 +invisibilitypotion,373,8206 +invisiblepotion,373,8206 +invpotion,373,8206 +invisibilitypot,373,8206 +invisiblepot,373,8206 +invpot,373,8206 +ipot,373,8206 +regenerationleveliipotion,373,8225 +regenerateleveliipotion,373,8225 +regenleveliipotion,373,8225 +regenerationlevel2potion,373,8225 +regeneratelevel2potion,373,8225 +regenlevel2potion,373,8225 +regenerationiipotion,373,8225 +regenerateiipotion,373,8225 +regeniipotion,373,8225 +regenerationleveliipot,373,8225 +regenerateleveliipot,373,8225 +regenleveliipot,373,8225 +regenerationlevel2pot,373,8225 +regeneratelevel2pot,373,8225 +regenlevel2pot,373,8225 +regenerationiipot,373,8225 +regenerateiipot,373,8225 +regeniipot,373,8225 +r2pot,373,8225 +swiftnessleveliipotion,373,8226 +swiftleveliipotion,373,8226 +speedleveliipotion,373,8226 +swiftnesslevel2potion,373,8226 +swiftlevel2potion,373,8226 +speedlevel2potion,373,8226 +swiftnessiipotion,373,8226 +swiftiipotion,373,8226 +speediipotion,373,8226 +swiftnessleveliipot,373,8226 +swiftleveliipot,373,8226 +speedleveliipot,373,8226 +swiftnesslevel2pot,373,8226 +swiftlevel2pot,373,8226 +speedlevel2pot,373,8226 +swiftnessiipot,373,8226 +swiftiipot,373,8226 +speediipot,373,8226 +sw2pot,373,8226 +poisonleveliipotion,373,8228 +acidleveliipotion,373,8228 +poisonlevel2potion,373,8228 +acidlevel2potion,373,8228 +poisoniipotion,373,8228 +acidiipotion,373,8228 +poisonleveliipot,373,8228 +acidleveliipot,373,8228 +poisonlevel2pot,373,8228 +acidlevel2pot,373,8228 +poisoniipot,373,8228 +acidiipot,373,8228 +p2pot,373,8228 +healingleveliipotion,373,8229 +healleveliipotion,373,8229 +healinglevel2potion,373,8229 +heallevel2potion,373,8229 +healingiipotion,373,8229 +healiipotion,373,8229 +healingleveliipot,373,8229 +healleveliipot,373,8229 +healinglevel2pot,373,8229 +heallevel2pot,373,8229 +healingiipot,373,8229 +healiipot,373,8229 +h2pot,373,8229 +strengthleveliipotion,373,8233 +strongleveliipotion,373,8233 +strleveliipotion,373,8233 +strengthlevel2potion,373,8233 +stronglevel2potion,373,8233 +strlevel2potion,373,8233 +strengthiipotion,373,8233 +strongiipotion,373,8233 +striipotion,373,8233 +strengthleveliipot,373,8233 +strongleveliipot,373,8233 +strleveliipot,373,8233 +strengthlevel2pot,373,8233 +stronglevel2pot,373,8233 +strlevel2pot,373,8233 +strengthiipot,373,8233 +strongiipot,373,8233 +striipot,373,8233 +st2pot,373,8233 +harmingleveliipotion,373,8236 +damageleveliipotion,373,8236 +dmgleveliipotion,373,8236 +harminglevel2potion,373,8236 +damagelevel2potion,373,8236 +dmglevel2potion,373,8236 +harmingiipotion,373,8236 +damageiipotion,373,8236 +dmgiipotion,373,8236 +harmingleveliipot,373,8236 +damageleveliipot,373,8236 +dmgleveliipot,373,8236 +harminglevel2pot,373,8236 +damagelevel2pot,373,8236 +dmglevel2pot,373,8236 +harmingiipot,373,8236 +damageiipot,373,8236 +dmgiipot,373,8236 +d2pot,373,8236 +regenerationextendedpotion,373,8257 +regenerateextendedpotion,373,8257 +regenextendepotion,373,8257 +regenerationexpotion,373,8257 +regenerateexpotion,373,8257 +regenexpotion,373,8257 +regenerationextendedpot,373,8257 +regenerateextendedpot,373,8257 +regenextendepot,373,8257 +regenerationexpot,373,8257 +regenerateexpot,373,8257 +regenexpot,373,8257 +repot,373,8257 +swiftnessextendedpotion,373,8258 +swiftextendedpotion,373,8258 +speedextendedpotion,373,8258 +swiftnessexpotion,373,8258 +swiftexpotion,373,8258 +speedexpotion,373,8258 +swiftnessextendedpot,373,8258 +swiftextendedpot,373,8258 +speedextendedpot,373,8258 +swiftnessexpot,373,8258 +swiftexpot,373,8258 +speedexpot,373,8258 +swepot,373,8258 +fireresistanceextendedpotion,373,8259 +fireresistextendedpotion,373,8259 +fireresextendedpotion,373,8259 +fireresistanceexpotion,373,8259 +fireresistexpotion,373,8259 +fireresexpotion,373,8259 +fireresistanceextendedpot,373,8259 +fireresistextendedpot,373,8259 +fireresextendedpot,373,8259 +fireresistanceexpot,373,8259 +fireresistexpot,373,8259 +fireresexpot,373,8259 +fepot,373,8259 +poisonextendedpotion,373,8260 +acidextendedpotion,373,8260 +poisonexpotion,373,8260 +acidexpotion,373,8260 +poisonextendedpot,373,8260 +acidextendedpot,373,8260 +poisonexpot,373,8260 +acidexpot,373,8260 +pepot,373,8260 +nightvisionextendedpotion,373,8262 +nvisionextendedpotion,373,8262 +nightvextendedpotion,373,8262 +darkvisionextendedpotion,373,8262 +dvisionextendedpotion,373,8262 +darkvextendedpotion,373,8262 +nightvisionexpotion,373,8262 +nvisionexpotion,373,8262 +nightvexpotion,373,8262 +darkvisionexpotion,373,8262 +dvisionexpotion,373,8262 +darkvexpotion,373,8262 +nightvisionextendedpot,373,8262 +nvisionextendedpot,373,8262 +nightvextendedpot,373,8262 +darkvisionextendedpot,373,8262 +dvisionextendedpot,373,8262 +darkvextendedpot,373,8262 +nightvisionexpot,373,8262 +nvisionexpot,373,8262 +nightvexpot,373,8262 +darkvisionexpot,373,8262 +dvisionexpot,373,8262 +darkvexpot,373,8262 +nepot,373,8262 +weaknessextendedpotion,373,8264 +weakextendedpotion,373,8264 +weaknessexpotion,373,8264 +weakexpotion,373,8264 +weaknessextendedpot,373,8264 +weakextendedpot,373,8264 +weaknessexpot,373,8264 +weakexpot,373,8264 +wepot,373,8264 +strengthextendedpotion,373,8265 +strongextendedpotion,373,8265 +strextendedpotion,373,8265 +strengthexpotion,373,8265 +strongexpotion,373,8265 +strexpotion,373,8265 +strengthextendedpot,373,8265 +strongextendedpot,373,8265 +strextendedpot,373,8265 +strengthexpot,373,8265 +strongexpot,373,8265 +strexpot,373,8265 +stepot,373,8265 +slownessextendedpotion,373,8266 +slowextenedpotion,373,8266 +slownessexpotion,373,8266 +slowexpotion,373,8266 +slownessextendedpot,373,8266 +slowextenedpot,373,8266 +slownessexpot,373,8266 +slowexpot,373,8266 +slepot,373,8266 +waterbreathingextendedpotion,373,8269 +waterbreathextendedpotion,373,8269 +breathingextendedpotion,373,8269 +breathextendedpotion,373,8269 +waterbreathingextendedpot,373,8269 +waterbreathextendedpot,373,8269 +breathingextendedpot,373,8269 +breathextendedpot,373,8269 +waterbreathingexpotion,373,8269 +waterbreathexpotion,373,8269 +breathingexpotion,373,8269 +breathexpotion,373,8269 +waterbreathingexpot,373,8269 +waterbreathexpot,373,8269 +breathingexpot,373,8269 +breathexpot,373,8269 +wbepot,373,8269 +invisibilityextendedpotion,373,8270 +invisibleextendedpotion,373,8270 +invextendedpotion,373,8270 +invisibilityexpotion,373,8270 +invisibleexpotion,373,8270 +invexpotion,373,8270 +invisibilityextendedpot,373,8270 +invisibleextendedpot,373,8270 +invextendedpot,373,8270 +invisibilityexpot,373,8270 +invisibleexpot,373,8270 +invexpot,373,8270 +iepot,373,8270 +regenerationdualbitpotion,373,8289 +regeneratedualbitpotion,373,8289 +regendualbitpotion,373,8289 +regenerationdbpotion,373,8289 +regeneratedbpotion,373,8289 +regendbpotion,373,8289 +regenerationdualbitpot,373,8289 +regeneratedualbitpot,373,8289 +regendualbitpot,373,8289 +regenerationdbpot,373,8289 +regeneratedbpot,373,8289 +regendbpot,373,8289 +rdbpot,373,8289 +swiftnessdualbitpotion,373,8290 +swiftdualbitpotion,373,8290 +speeddualbitpotion,373,8290 +swiftnessdualbitpot,373,8290 +swiftdualbitpot,373,8290 +speeddualbitpot,373,8290 +swiftnessdbpotion,373,8290 +swiftdbpotion,373,8290 +speeddbpotion,373,8290 +swiftnessdbpot,373,8290 +swiftdbpot,373,8290 +speeddbpot,373,8290 +swdbpot,373,8290 +poisondualbitpotion,373,8292 +aciddualbitpotion,373,8292 +poisondualbitpot,373,8292 +aciddualbitpot,373,8292 +poisondbpotion,373,8292 +aciddbpotion,373,8292 +poisondbpot,373,8292 +aciddbpot,373,8292 +pdbpot,373,8292 +strengthdualbitpotion,373,8297 +strongdualbitpotion,373,8297 +strdualbitpotion,373,8297 +strengthdualbitpot,373,8297 +strongdualbitpot,373,8297 +strdualbitpot,373,8297 +strengthdbpotion,373,8297 +strongdbpotion,373,8297 +strdbpotion,373,8297 +strengthdbpot,373,8297 +strongdbpot,373,8297 +strdbpot,373,8297 +stdbpot,373,8297 +splashmundanepotion,373,16384 +splmundanepotion,373,16384 +splashregenerationpotion,373,16385 +splashregeneratepotion,373,16385 +splashregenpotion,373,16385 +splashregenerationpot,373,16385 +splashregeneratepot,373,16385 +splashregenpot,373,16385 +regenerationsplashpotion,373,16385 +regeneratesplashpotion,373,16385 +regensplashpotion,373,16385 +splregenerationpotion,373,16385 +splregeneratepotion,373,16385 +splregenpotion,373,16385 +splregenerationpot,373,16385 +splregeneratepot,373,16385 +splregenpot,373,16385 +sprpot,373,16385 +splashswiftnesspotion,373,16386 +splashswiftpotion,373,16386 +splashspeedpotion,373,16386 +splashswiftnesspot,373,16386 +splashswiftpot,373,16386 +splashspeedpot,373,16386 +splswiftnesspotion,373,16386 +splswiftpotion,373,16386 +splspeedpotion,373,16386 +splswiftnesspot,373,16386 +splswiftpot,373,16386 +splspeedpot,373,16386 +spswpot,373,16386 +splashfireresistancepotion,373,16387 +splashfireresistpotion,373,16387 +splashfirerespotion,373,16387 +splashfireresistancepot,373,16387 +splashfireresistpot,373,16387 +splashfirerespot,373,16387 +splfireresistancepotion,373,16387 +splfireresistpotion,373,16387 +splfirerespotion,373,16387 +splfireresistancepot,373,16387 +splfireresistpot,373,16387 +splfirerespot,373,16387 +spfpot,373,16387 +splashpoisonpotion,373,16388 +splashacidpotion,373,16388 +splashpoisonpot,373,16388 +splashacidpot,373,16388 +splpoisonpotion,373,16388 +splacidpotion,373,16388 +splpoisonpot,373,16388 +splacidpot,373,16388 +spppot,373,16388 +splashhealingpotion,373,16389 +splashhealpotion,373,16389 +splashlifepotion,373,16389 +splashhealingpot,373,16389 +splashhealpot,373,16389 +splashlifepot,373,16389 +splhealingpotion,373,16389 +splhealpotion,373,16389 +spllifepotion,373,16389 +splhealingpot,373,16389 +splhealpot,373,16389 +spllifepot,373,16389 +sphpot,373,16389 +splashclearpotion,373,16390 +splashclearpot,373,16390 +splclearpotion,373,16390 +splclearpot,373,16390 +splashnightvisionpotion,373,16390 +splashnvisionpotion,373,16390 +splashnightvpotion,373,16390 +splashdarkvisionpotion,373,16390 +splashdvisionpotion,373,16390 +splashdarkvpotion,373,16390 +splashnightvisionpot,373,16390 +splashnvisionpot,373,16390 +splashnightvpot,373,16390 +splashdarkvisionpot,373,16390 +splashdvisionpot,373,16390 +splashdarkvpot,373,16390 +splnightvisionpotion,373,16390 +splnvisionpotion,373,16390 +splnightvpotion,373,16390 +spldarkvisionpotion,373,16390 +spldvisionpotion,373,16390 +spldarkvpotion,373,16390 +splnightvisionpot,373,16390 +splnvisionpot,373,16390 +splnightvpot,373,16390 +spldarkvisionpot,373,16390 +spldvisionpot,373,16390 +spldarkvpot,373,16390 +spnpot,373,16390 +splashclearextendedpotion,373,16391 +splashclearexpotion,373,16391 +splashclear2potion,373,16391 +splashclearextendedpot,373,16391 +splashclearexpot,373,16391 +splashclear2pot,373,16391 +splclearextendedpotion,373,16391 +splclearexpotion,373,16391 +splclear2potion,373,16391 +splclearextendedpot,373,16391 +splclearexpot,373,16391 +splclear2pot,373,16391 +splashweaknesspotion,373,16392 +splashweakpotion,373,16392 +splashweaknesspot,373,16392 +splashweakpot,373,16392 +splweaknesspotion,373,16392 +splweakpotion,373,16392 +splweaknesspot,373,16392 +splweakpot,373,16392 +spwpot,373,16392 +splashstrengthpotion,373,16393 +splashstrongpotion,373,16393 +splashstrpotion,373,16393 +splashstrengthpot,373,16393 +splashstrongpot,373,16393 +splashstrpot,373,16393 +splstrengthpotion,373,16393 +splstrongpotion,373,16393 +splstrpotion,373,16393 +splstrengthpot,373,16393 +splstrongpot,373,16393 +splstrpot,373,16393 +spstpot,373,16393 +splashslownesspotion,373,16394 +splashslowpotion,373,16394 +splashslownesspot,373,16394 +splashslowpot,373,16394 +splslownesspotion,373,16394 +splslowpotion,373,16394 +splslownesspot,373,16394 +splslowpot,373,16394 +spslpot,373,16394 +splashdiffusepotion,373,16395 +splashdiffusepot,373,16395 +spldiffusepotion,373,16395 +spldiffusepot,373,16395 +splashharmingpotion,373,16396 +splashdamagepotion,373,16396 +splashdmgpotion,373,16396 +splashharmingpot,373,16396 +splashdamagepot,373,16396 +splashdmgpot,373,16396 +splharmingpotion,373,16396 +spldamagepotion,373,16396 +spldmgpotion,373,16396 +splharmingpot,373,16396 +spldamagepot,373,16396 +spldmgpot,373,16396 +spdpot,373,16396 +splashartlesspotion,373,16397 +splashartlesspot,373,16397 +splartlesspotion,373,16397 +splartlesspot,373,16397 +splashwaterbreathingpotion,373,16397 +splashwaterbreathpotion,373,16397 +splashbreathingpotion,373,16397 +splashbreathpotion,373,16397 +splashwaterbreathingpot,373,16397 +splashwaterbreathpot,373,16397 +splashbreathingpot,373,16397 +splashbreathpot,373,16397 +splwaterbreathingpotion,373,16397 +splwaterbreathpotion,373,16397 +splbreathingpotion,373,16397 +splbreathpotion,373,16397 +splwaterbreathingpot,373,16397 +splwaterbreathpot,373,16397 +splbreathingpot,373,16397 +splbreathpot,373,16397 +spwbpot,373,16397 +splashthinpotion,373,16398 +splashthinpot,373,16398 +splthinpotion,373,16398 +splthinpot,373,16398 +splashinvisibilitypotion,373,16398 +splashinvisiblepotion,373,16398 +splashinvpotion,373,16398 +splashinvisibilitypot,373,16398 +splashinvisiblepot,373,16398 +splashinvpot,373,16398 +splinvisibilitypotion,373,16398 +splinvisiblepotion,373,16398 +splinvpotion,373,16398 +splinvisibilitypot,373,16398 +splinvisiblepot,373,16398 +splinvpot,373,16398 +spipot,373,16398 +splashthinextendedpotion,373,16399 +splashthinexpotion,373,16399 +splashthin2potion,373,16399 +splashthinextendedpot,373,16399 +splashthinexpot,373,16399 +splashthin2pot,373,16399 +splthinextendedpotion,373,16399 +splthinexpotion,373,16399 +splthin2potion,373,16399 +splthinextendedpot,373,16399 +splthinexpot,373,16399 +splthin2pot,373,16399 +splashawkwardpotion,373,16400 +splashawkwardpot,373,16400 +splawkwardpotion,373,16400 +splawkwardpot,373,16400 +splashbunglingpotion,373,16406 +splashbunglingpot,373,16406 +splbunglingpotion,373,16406 +splbunglingpot,373,16406 +splashbunglingextendedpotion,373,16407 +splashbunglingexpotion,373,16407 +splashbungling2potion,373,16407 +splashbunglingextendedpot,373,16407 +splashbunglingexpot,373,16407 +splashbungling2pot,373,16407 +splbunglingextendedpotion,373,16407 +splbunglingexpotion,373,16407 +splbungling2potion,373,16407 +splbunglingextendedpot,373,16407 +splbunglingexpot,373,16407 +splbungling2pot,373,16407 +splashsmoothpotion,373,16411 +splashsmoothpot,373,16411 +splsmoothpotion,373,16411 +splsmoothpot,373,16411 +splashsuavepotion,373,16413 +splashsuavepot,373,16413 +splsuavepotion,373,16413 +splsuavepot,373,16413 +splashdebonairpotion,373,16414 +splashdebonairpot,373,16414 +spldebonairpotion,373,16414 +spldebonairpot,373,16414 +splashdebonairextendedpotion,373,16415 +splashdebonairexpotion,373,16415 +splashdebonair2potion,373,16415 +splashdebonairextendedpot,373,16415 +splashdebonairexpot,373,16415 +splashdebonair2pot,373,16415 +spldebonairextendedpotion,373,16415 +spldebonairexpotion,373,16415 +spldebonair2potion,373,16415 +spldebonairextendedpot,373,16415 +spldebonairexpot,373,16415 +spldebonair2pot,373,16415 +splashthickpotion,373,16416 +splashthickpot,373,16416 +splthickpotion,373,16416 +splthickpot,373,16416 +splashregenerationleveliipotion,373,16417 +splashregenerateleveliipotion,373,16417 +splashregenleveliipotion,373,16417 +splashregenerationlevel2potion,373,16417 +splashregeneratelevel2potion,373,16417 +splashregenlevel2potion,373,16417 +splashregenerationiipotion,373,16417 +splashregenerateiipotion,373,16417 +splashregeniipotion,373,16417 +splashregenerationleveliipot,373,16417 +splashregenerateleveliipot,373,16417 +splashregenleveliipot,373,16417 +splashregenerationlevel2pot,373,16417 +splashregeneratelevel2pot,373,16417 +splashregenlevel2pot,373,16417 +splashregenerationiipot,373,16417 +splashregenerateiipot,373,16417 +splashregeniipot,373,16417 +splregenerationleveliipotion,373,16417 +splregenerateleveliipotion,373,16417 +splregenleveliipotion,373,16417 +splregenerationlevel2potion,373,16417 +splregeneratelevel2potion,373,16417 +splregenlevel2potion,373,16417 +splregenerationiipotion,373,16417 +splregenerateiipotion,373,16417 +splregeniipotion,373,16417 +splregenerationleveliipot,373,16417 +splregenerateleveliipot,373,16417 +splregenleveliipot,373,16417 +splregenerationlevel2pot,373,16417 +splregeneratelevel2pot,373,16417 +splregenlevel2pot,373,16417 +splregenerationiipot,373,16417 +splregenerateiipot,373,16417 +splregeniipot,373,16417 +spr2pot,373,16417 +splashswiftnessleveliipotion,373,16418 +splashswiftleveliipotion,373,16418 +splashspeedleveliipotion,373,16418 +splashswiftnesslevel2potion,373,16418 +splashswiftlevel2potion,373,16418 +splashspeedlevel2potion,373,16418 +splashswiftnessiipotion,373,16418 +splashswiftiipotion,373,16418 +splashspeediipotion,373,16418 +splashswiftnessleveliipot,373,16418 +splashswiftleveliipot,373,16418 +splashspeedleveliipot,373,16418 +splashswiftnesslevel2pot,373,16418 +splashswiftlevel2pot,373,16418 +splashspeedlevel2pot,373,16418 +splashswiftnessiipot,373,16418 +splashswiftiipot,373,16418 +splashspeediipot,373,16418 +splswiftnessleveliipotion,373,16418 +splswiftleveliipotion,373,16418 +splspeedleveliipotion,373,16418 +splswiftnesslevel2potion,373,16418 +splswiftlevel2potion,373,16418 +splspeedlevel2potion,373,16418 +splswiftnessiipotion,373,16418 +splswiftiipotion,373,16418 +splspeediipotion,373,16418 +splswiftnessleveliipot,373,16418 +splswiftleveliipot,373,16418 +splspeedleveliipot,373,16418 +splswiftnesslevel2pot,373,16418 +splswiftlevel2pot,373,16418 +splspeedlevel2pot,373,16418 +splswiftnessiipot,373,16418 +splswiftiipot,373,16418 +splspeediipot,373,16418 +spsw2pot,373,16418 +splashpoisonleveliipotion,373,16420 +splashacidleveliipotion,373,16420 +splashpoisonlevel2potion,373,16420 +splashacidlevel2potion,373,16420 +splashpoisoniipotion,373,16420 +splashacidiipotion,373,16420 +splashpoisonleveliipot,373,16420 +splashacidleveliipot,373,16420 +splashpoisonlevel2pot,373,16420 +splashacidlevel2pot,373,16420 +splashpoisoniipot,373,16420 +splashacidiipot,373,16420 +splpoisonleveliipotion,373,16420 +splacidleveliipotion,373,16420 +splpoisonlevel2potion,373,16420 +splcidlevel2potion,373,16420 +splpoisoniipotion,373,16420 +splacidiipotion,373,16420 +splpoisonleveliipot,373,16420 +splacidleveliipot,373,16420 +splpoisonlevel2pot,373,16420 +splacidlevel2pot,373,16420 +splpoisoniipot,373,16420 +splacidiipot,373,16420 +spp2pot,373,16420 +splashhealingleveliipotion,373,16421 +splashhealleveliipotion,373,16421 +splashhealinglevel2potion,373,16421 +splashheallevel2potion,373,16421 +splashhealingiipotion,373,16421 +splashhealiipotion,373,16421 +splashhealingleveliipot,373,16421 +splashhealleveliipot,373,16421 +splashhealinglevel2pot,373,16421 +splashheallevel2pot,373,16421 +splashhealingiipot,373,16421 +splashhealiipot,373,16421 +splhealingleveliipotion,373,16421 +splhealleveliipotion,373,16421 +splhealinglevel2potion,373,16421 +splheallevel2potion,373,16421 +splhealingiipotion,373,16421 +splhealiipotion,373,16421 +splhealingleveliipot,373,16421 +splhealleveliipot,373,16421 +splhealinglevel2pot,373,16421 +splheallevel2pot,373,16421 +splhealingiipot,373,16421 +splhealiipot,373,16421 +sph2pot,373,16421 +splashcharmingpotion,373,16422 +splashcharmingpot,373,16422 +splcharmingpotion,373,16422 +splcharmingpot,373,16422 +splashcharmingextendedpotion,373,16423 +splashcharmingexpotion,373,16423 +splashcharming2potion,373,16423 +splashcharmingextendedpot,373,16423 +splashcharmingexpot,373,16423 +splashcharming2pot,373,16423 +splcharmingextendedpotion,373,16423 +splcharmingexpotion,373,16423 +splcharming2potion,373,16423 +splcharmingextendedpot,373,16423 +splcharmingexpot,373,16423 +splcharming2pot,373,16423 +splashstrengthleveliipotion,373,16425 +splashstrongleveliipotion,373,16425 +splashstrleveliipotion,373,16425 +splashstrengthlevel2potion,373,16425 +splashstronglevel2potion,373,16425 +splashstrlevel2potion,373,16425 +splashstrengthiipotion,373,16425 +splashstrongiipotion,373,16425 +splashstriipotion,373,16425 +splashstrengthleveliipot,373,16425 +splashstrongleveliipot,373,16425 +splashstrleveliipot,373,16425 +splashstrengthlevel2pot,373,16425 +splashstronglevel2pot,373,16425 +splashstrlevel2pot,373,16425 +splashstrengthiipot,373,16425 +splashstrongiipot,373,16425 +splashstriipot,373,16425 +splstrengthleveliipotion,373,16425 +splstrongleveliipotion,373,16425 +splstrleveliipotion,373,16425 +splstrengthlevel2potion,373,16425 +splstronglevel2potion,373,16425 +splstrlevel2potion,373,16425 +splstrengthiipotion,373,16425 +splstrongiipotion,373,16425 +splstriipotion,373,16425 +splstrengthleveliipot,373,16425 +splstrongleveliipot,373,16425 +splstrleveliipot,373,16425 +splstrengthlevel2pot,373,16425 +splstronglevel2pot,373,16425 +splstrlevel2pot,373,16425 +splstrengthiipot,373,16425 +splstrongiipot,373,16425 +splstriipot,373,16425 +spst2pot,373,16425 +splashrefinedpotion,373,16427 +splashrefinedpot,373,16427 +splrefinedpotion,373,16427 +splrefinedpot,373,16427 +splashharmingleveliipotion,373,16428 +splashdamageleveliipotion,373,16428 +splashdmgleveliipotion,373,16428 +splashharminglevel2potion,373,16428 +splashdamagelevel2potion,373,16428 +splashdmglevel2potion,373,16428 +splashharmingiipotion,373,16428 +splashdamageiipotion,373,16428 +splashdmgiipotion,373,16428 +splashharmingleveliipot,373,16428 +splashdamageleveliipot,373,16428 +splashdmgleveliipot,373,16428 +splashharminglevel2pot,373,16428 +splashdamagelevel2pot,373,16428 +splashdmglevel2pot,373,16428 +splashharmingiipot,373,16428 +splashdamageiipot,373,16428 +splashdmgiipot,373,16428 +splharmingleveliipotion,373,16428 +spldamageleveliipotion,373,16428 +spldmgleveliipotion,373,16428 +splharminglevel2potion,373,16428 +spldamagelevel2potion,373,16428 +spldmglevel2potion,373,16428 +splharmingiipotion,373,16428 +spldamageiipotion,373,16428 +spldmgiipotion,373,16428 +splharmingleveliipot,373,16428 +spldamageleveliipot,373,16428 +spldmgleveliipot,373,16428 +splharminglevel2pot,373,16428 +spldamagelevel2pot,373,16428 +spldmglevel2pot,373,16428 +splharmingiipot,373,16428 +spldamageiipot,373,16428 +spldmgiipot,373,16428 +spd2pot,373,16428 +splashcordialpotion,373,16429 +splashcordialpot,373,16429 +splcordialpotion,373,16429 +splcordialpot,373,16429 +splashsparklingpotion,373,16430 +splashsparklingpot,373,16430 +splsparklingpotion,373,16430 +splsparklingpot,373,16430 +splashsparklingextendedpotion,373,16431 +splashsparklingexpotion,373,16431 +splashsparkling2potion,373,16431 +splashsparklingextendedpot,373,16431 +splashsparklingexpot,373,16431 +splashsparkling2pot,373,16431 +splsparklingextendedpotion,373,16431 +splsparklingexpotion,373,16431 +splsparkling2potion,373,16431 +splsparklingextendedpot,373,16431 +splsparklingexpot,373,16431 +splsparkling2pot,373,16431 +splashpotentpotion,373,16432 +splashpotentpot,373,16432 +splpotentpotion,373,16432 +splpotentpot,373,16432 +splashrankpotion,373,16438 +splashrankpot,373,16438 +splrankpotion,373,16438 +splrankpot,373,16438 +splashrankextendedpotion,373,16439 +splashrankexpotion,373,16439 +splashrank2potion,373,16439 +splashrankextendedpot,373,16439 +splashrankexpot,373,16439 +splashrank2pot,373,16439 +splrankextendedpotion,373,16439 +splrankexpotion,373,16439 +splrank2potion,373,16439 +splrankextendedpot,373,16439 +splrankexpot,373,16439 +splrank2pot,373,16439 +splashacridpotion,373,16443 +splashacridpot,373,16443 +splacridpotion,373,16443 +splacridpot,373,16443 +splashgrosspotion,373,16445 +splashgrosspot,373,16445 +splgrosspotion,373,16445 +splgrosspot,373,16445 +splashstinkypotion,373,16446 +splashstinkypot,373,16446 +splstinkypotion,373,16446 +splstinkypot,373,16446 +splashstinkyextendedpotion,373,16447 +splashstinkyexpotion,373,16447 +splashstinky2potion,373,16447 +splashstinkyextendedpot,373,16447 +splashstinkyexpot,373,16447 +splashstinky2pot,373,16447 +splstinkyextendedpotion,373,16447 +splstinkyexpotion,373,16447 +splstinky2potion,373,16447 +splstinkyextendedpot,373,16447 +splstinkyexpot,373,16447 +splstinky2pot,373,16447 +splashmundaneextendedpotion,373,16448 +splashmundaneexpotion,373,16448 +splashmundane2potion,373,16448 +splashmundaneextendedpot,373,16448 +splashmundaneexpot,373,16448 +splashmundane2pot,373,16448 +splmundaneextendedpotion,373,16448 +splmundaneexpotion,373,16448 +splmundane2potion,373,16448 +splmundaneextendedpot,373,16448 +splmundaneexpot,373,16448 +splmundane2pot,373,16448 +splashregenerationextendedpotion,373,16449 +splashregenerateextendedpotion,373,16449 +splashregenextendepotion,373,16449 +splashregenerationexpotion,373,16449 +splashregenerateexpotion,373,16449 +splashregenexpotion,373,16449 +splashregenerationextendedpot,373,16449 +splashregenerateextendedpot,373,16449 +splashregenextendepot,373,16449 +splashregenerationexpot,373,16449 +splashregenerateexpot,373,16449 +splashregenexpot,373,16449 +splregenerationextendedpotion,373,16449 +splregenerateextendedpotion,373,16449 +splregenextendepotion,373,16449 +splregenerationexpotion,373,16449 +splregenerateexpotion,373,16449 +splregenexpotion,373,16449 +splregenerationextendedpot,373,16449 +splregenerateextendedpot,373,16449 +splregenextendepot,373,16449 +splregenerationexpot,373,16449 +splregenerateexpot,373,16449 +splregenexpot,373,16449 +sprepot,373,16449 +splashswiftnessextendedpotion,373,16450 +splashswiftextendedpotion,373,16450 +splashspeedextendedpotion,373,16450 +splashswiftnessexpotion,373,16450 +splashswiftexpotion,373,16450 +splashspeedexpotion,373,16450 +splashswiftnessextendedpot,373,16450 +splashswiftextendedpot,373,16450 +splashspeedextendedpot,373,16450 +splashswiftnessexpot,373,16450 +splashswiftexpot,373,16450 +splashspeedexpot,373,16450 +splswiftnessextendedpotion,373,16450 +splswiftextendedpotion,373,16450 +splspeedextendedpotion,373,16450 +splswiftnessexpotion,373,16450 +splswiftexpotion,373,16450 +splspeedexpotion,373,16450 +splswiftnessextendedpot,373,16450 +splswiftextendedpot,373,16450 +splspeedextendedpot,373,16450 +splswiftnessexpot,373,16450 +splswiftexpot,373,16450 +splspeedexpot,373,16450 +spswepot,373,16450 +splashfireresistanceextendedpotion,373,16451 +splashfireresistextendedpotion,373,16451 +splashfireresextendedpotion,373,16451 +splashfireresistanceexpotion,373,16451 +splashfireresistexpotion,373,16451 +splashfireresexpotion,373,16451 +splashfireresistanceextendedpot,373,16451 +splashfireresistextendedpot,373,16451 +splashfireresextendedpot,373,16451 +splashfireresistanceexpot,373,16451 +splashfireresistexpot,373,16451 +splashfireresexpot,373,16451 +splfireresistanceextendedpotion,373,16451 +splfireresistextendedpotion,373,16451 +splfireresextendedpotion,373,16451 +splfireresistanceexpotion,373,16451 +splfireresistexpotion,373,16451 +splfireresexpotion,373,16451 +splfireresistanceextendedpot,373,16451 +splfireresistextendedpot,373,16451 +splfireresextendedpot,373,16451 +splfireresistanceexpot,373,16451 +splfireresistexpot,373,16451 +splfireresexpot,373,16451 +spfepot,373,16451 +splashpoisonextendedpotion,373,16452 +splashacidextendedpotion,373,16452 +splashpoisonexpotion,373,16452 +splashacidexpotion,373,16452 +splashpoisonextendedpot,373,16452 +splashacidextendedpot,373,16452 +splashpoisonexpot,373,16452 +splashacidexpot,373,16452 +splpoisonextendedpotion,373,16452 +splacidextendedpotion,373,16452 +splpoisonexpotion,373,16452 +splacidexpotion,373,16452 +splpoisonextendedpot,373,16452 +splacidextendedpot,373,16452 +splpoisonexpot,373,16452 +splacidexpot,373,16452 +sppepot,373,16452 +splashnightvisionextendedpotion,373,16454 +splashnvisionextendedpotion,373,16454 +splashnightvextendedpotion,373,16454 +splashdarkvisionextendedpotion,373,16454 +splashdvisionextendedpotion,373,16454 +splashdarkvextendedpotion,373,16454 +splashnightvisionextendedpot,373,16454 +splashnvisionextendedpot,373,16454 +splashnightvextendedpot,373,16454 +splashdarkvisionextendedpot,373,16454 +splashdvisionextendedpot,373,16454 +splashdarkvextendedpot,373,16454 +splashnightvisionexpotion,373,16454 +splashnvisionexpotion,373,16454 +splashnightvexpotion,373,16454 +splashdarkvisionexpotion,373,16454 +splashdvisionexpotion,373,16454 +splashdarkvexpotion,373,16454 +splashnightvisionexpot,373,16454 +splashnvisionexpot,373,16454 +splashnightvexpot,373,16454 +splashdarkvisionexpot,373,16454 +splashdvisionexpot,373,16454 +splashdarkvexpot,373,16454 +splnightvisionextendedpotion,373,16454 +splnvisionextendedpotion,373,16454 +splnightvextendedpotion,373,16454 +spldarkvisionextendedpotion,373,16454 +spldvisionextendedpotion,373,16454 +spldarkvextendedpotion,373,16454 +splnightvisionextendedpot,373,16454 +splnvisionextendedpot,373,16454 +splnightvextendedpot,373,16454 +spldarkvisionextendedpot,373,16454 +spldvisionextendedpot,373,16454 +spldarkvextendedpot,373,16454 +splnightvisionexpotion,373,16454 +splnvisionexpotion,373,16454 +splnightvexpotion,373,16454 +spldarkvisionexpotion,373,16454 +spldvisionexpotion,373,16454 +spldarkvexpotion,373,16454 +splnightvisionexpot,373,16454 +splnvisionexpot,373,16454 +splnightvexpot,373,16454 +spldarkvisionexpot,373,16454 +spldvisionexpot,373,16454 +spldarkvexpot,373,16454 +spnepot,373,16454 +splashweaknessextendedpotion,373,16456 +splashweakextendedpotion,373,16456 +splashweaknessexpotion,373,16456 +splashweakexpotion,373,16456 +splashweaknessextendedpot,373,16456 +splashweakextendedpot,373,16456 +splashweaknessexpot,373,16456 +splashweakexpot,373,16456 +splweaknessextendedpotion,373,16456 +sphweakextendedpotion,373,16456 +splweaknessexpotion,373,16456 +splweakexpotion,373,16456 +splweaknessextendedpot,373,16456 +splweakextendedpot,373,16456 +splweaknessexpot,373,16456 +splweakexpot,373,16456 +spwepot,373,16456 +splashstrengthextendedpotion,373,16457 +splashstrongextendedpotion,373,16457 +splashstrextendedpotion,373,16457 +splashstrengthexpotion,373,16457 +splashstrongexpotion,373,16457 +splashstrexpotion,373,16457 +splashstrengthextendedpot,373,16457 +splashstrongextendedpot,373,16457 +splashstrextendedpot,373,16457 +splashstrengthexpot,373,16457 +splashstrongexpot,373,16457 +splashstrexpot,373,16457 +splstrengthextendedpotion,373,16457 +splstrongextendedpotion,373,16457 +splstrextendedpotion,373,16457 +splstrengthexpotion,373,16457 +splstrongexpotion,373,16457 +splstrexpotion,373,16457 +splstrengthextendedpot,373,16457 +splstrongextendedpot,373,16457 +splstrextendedpot,373,16457 +splstrengthexpot,373,16457 +splstrongexpot,373,16457 +splstrexpot,373,16457 +spstepot,373,16457 +splashslownessextendedpotion,373,16458 +splashslowextenedpotion,373,16458 +splashslownessexpotion,373,16458 +splashslowexpotion,373,16458 +splashslownessextendedpot,373,16458 +splashslowextenedpot,373,16458 +splashslownessexpot,373,16458 +splashslowexpot,373,16458 +splslownessextendedpotion,373,16458 +splslowextenedpotion,373,16458 +splslownessexpotion,373,16458 +splslowexpotion,373,16458 +splslownessextendedpot,373,16458 +splslowextenedpot,373,16458 +splslownessexpot,373,16458 +splslowexpot,373,16458 +spslepot,373,16458 +splashwaterbreathingextendedpotion,373,16461 +splashwaterbreathextendedpotion,373,16461 +splashbreathingextendedpotion,373,16461 +splashbreathextendedpotion,373,16461 +splashwaterbreathingextendedpot,373,16461 +splashwaterbreathextendedpot,373,16461 +splashbreathingextendedpot,373,16461 +splashbreathextendedpot,373,16461 +splwaterbreathingextendedpotion,373,16461 +splwaterbreathextendedpotion,373,16461 +splbreathingextendedpotion,373,16461 +splbreathextendedpotion,373,16461 +splwaterbreathingextendedpot,373,16461 +splwaterbreathextendedpot,373,16461 +splbreathingextendedpot,373,16461 +splbreathextendedpot,373,16461 +splashwaterbreathingexpotion,373,16461 +splashwaterbreathexpotion,373,16461 +splashbreathingexpotion,373,16461 +splashbreathexpotion,373,16461 +splashwaterbreathingexpot,373,16461 +splashwaterbreathexpot,373,16461 +splashbreathingexpot,373,16461 +splashbreathexpot,373,16461 +splwaterbreathingexpotion,373,16461 +splwaterbreathexpotion,373,16461 +splbreathingexpotion,373,16461 +splbreathexpotion,373,16461 +splwaterbreathingexpot,373,16461 +splwaterbreathexpot,373,16461 +splbreathingexpot,373,16461 +splbreathexpot,373,16461 +spwbepot,373,16461 +splashinvisibilityextendedpotion,373,16462 +splashinvisibleextendedpotion,373,16462 +splashinvextendedpotion,373,16462 +splashinvisibilityextendedpot,373,16462 +splashinvisibleextendedpot,373,16462 +splashinvextendedpot,373,16462 +splashinvisibilityexpotion,373,16462 +splashinvisibleexpotion,373,16462 +splashinvexpotion,373,16462 +splashinvisibilityexpot,373,16462 +splashinvisibleexpot,373,16462 +splashinvexpot,373,16462 +splinvisibilityextendedpotion,373,16462 +splinvisibleextendedpotion,373,16462 +splinvextendedpotion,373,16462 +splinvisibilityextendedpot,373,16462 +splinvisibleextendedpot,373,16462 +splinvextendedpot,373,16462 +splinvisibilityexpotion,373,16462 +splinvisibleexpotion,373,16462 +splinvexpotion,373,16462 +splinvisibilityexpot,373,16462 +splinvisibleexpot,373,16462 +splinvexpot,373,16462 +spiepot,373,16462 +splashregenerationdualbitpotion,373,16481 +splashregeneratedualbitpotion,373,16481 +splashregendualbitpotion,373,16481 +splashregenerationdualbitpot,373,16481 +splashregeneratedualbitpot,373,16481 +splashregendualbitpot,373,16481 +splregenerationdualbitpotion,373,16481 +splregeneratedualbitpotion,373,16481 +splregendualbitpotion,373,16481 +splregenerationdualbitpot,373,16481 +splregeneratedualbitpot,373,16481 +splregendualbitpot,373,16481 +splashregenerationdbpotion,373,16481 +splashregeneratedbpotion,373,16481 +splashregendbpotion,373,16481 +splashregenerationdbpot,373,16481 +splashregeneratedbpot,373,16481 +splashregendbpot,373,16481 +splregenerationdbpotion,373,16481 +splregeneratedbpotion,373,16481 +splregendbpotion,373,16481 +splregenerationdbpot,373,16481 +splregeneratedbpot,373,16481 +splregendbpot,373,16481 +sprdbpot,373,16481 +splashswiftnessdualbitpotion,373,16482 +splashswiftdualbitpotion,373,16482 +splashspeeddualbitpotion,373,16482 +splashswiftnessdualbitpot,373,16482 +splashswiftdualbitpot,373,16482 +splashspeeddualbitpot,373,16482 +splswiftnessdualbitpotion,373,16482 +splswiftdualbitpotion,373,16482 +splspeeddualbitpotion,373,16482 +splswiftnessdualbitpot,373,16482 +splswiftdualbitpot,373,16482 +splspeeddualbitpot,373,16482 +splashswiftnessdbpotion,373,16482 +splashswiftdbpotion,373,16482 +splashspeeddbpotion,373,16482 +splashswiftnessdbpot,373,16482 +splashswiftdbpot,373,16482 +splashspeeddbpot,373,16482 +splswiftnessdbpotion,373,16482 +splswiftdbpotion,373,16482 +splspeeddbpotion,373,16482 +splswiftnessdbpot,373,16482 +splswiftdbpot,373,16482 +splspeeddbpot,373,16482 +spswdbpot,373,16482 +splashpoisondualbitpotion,373,16484 +splashaciddualbitpotion,373,16484 +splashpoisondualbitpot,373,16484 +splashaciddualbitpot,373,16484 +splpoisondualbitpotion,373,16484 +splaciddualbitpotion,373,16484 +splpoisondualbitpot,373,16484 +splaciddualbitpot,373,16484 +splashpoisondbpotion,373,16484 +splashaciddbpotion,373,16484 +splashpoisondbpot,373,16484 +splashaciddbpot,373,16484 +splpoisondbpotion,373,16484 +splaciddbpotion,373,16484 +splpoisondbpot,373,16484 +splaciddbpot,373,16484 +sppdbpot,373,16484 +splashstrengthdualbitpotion,373,16489 +splashstrongdualbitpotion,373,16489 +splashstrdualbitpotion,373,16489 +splashstrengthdualbitpot,373,16489 +splashstrongdualbitpot,373,16489 +splashstrdualbitpot,373,16489 +splstrengthdualbitpotion,373,16489 +splstrongdualbitpotion,373,16489 +splstrdualbitpotion,373,16489 +splstrengthdualbitpot,373,16489 +splstrongdualbitpot,373,16489 +splstrdualbitpot,373,16489 +splashstrengthdbpotion,373,16489 +splashstrongdbpotion,373,16489 +splashstrdbpotion,373,16489 +splashstrengthdbpot,373,16489 +splashstrongdbpot,373,16489 +splashstrdbpot,373,16489 +splstrengthdbpotion,373,16489 +splstrongdbpotion,373,16489 +splstrdbpotion,373,16489 +splstrengthdbpot,373,16489 +splstrongdbpot,373,16489 +splstrdbpot,373,16489 +spstdbpot,373,16489 +glassbottle,374,0 +bottle,374,0 +gbottle,374,0 +gvase,374,0 +vase,374,0 +glassvase,374,0 +emptyglassbottle,374,0 +emptybottle,374,0 +emptygbottle,374,0 +emptygvase,374,0 +emptyvase,374,0 +emptyglassvase,374,0 +eglassbottle,374,0 +ebottle,374,0 +egbottle,374,0 +egvase,374,0 +evase,374,0 +eglassvase,374,0 +spidereye,375,0 +eyeofspider,375,0 +seye,375,0 +fermentedspidereye,376,0 +craftedspidereye,376,0 +fspidereye,376,0 +cspidereye,376,0 +fermentedeyeofspider,376,0 +craftedeyeofspider,376,0 +feyeofspider,376,0 +ceyeofspider,376,0 +fermentedseye,376,0 +craftedseye,376,0 +fseye,376,0 +cseye,376,0 +blazepowder,377,0 +blazedust,377,0 +goldpowder,377,0 +golddust,377,0 +gdust,377,0 +gpowder,377,0 +bpowder,377,0 +bdust,377,0 +magmacream,378,0 +goldcream,378,0 +blazecream,378,0 +mcream,378,0 +gcream,378,0 +bcream,378,0 +combinedcream,378,0 +ccream,378,0 +bstand,379,0 +pstand,379,0 +brewingstand,379,0 +potionstand,379,0 +cauldron,380,0 +steelcauldron,380,0 +ironcauldron,380,0 +icauldron,380,0 +scauldron,380,0 +potioncauldron,380,0 +pcauldron,380,0 +eyeofender,381,0 +endereye,381,0 +endeye,381,0 +evilendereye,381,0 +evileyeofender,381,0 +evilenderpearl,381,0 +eeye,381,0 +eofender,381,0 +glisteringmelon,382,0 +speckledmelon,382,0 +goldmelon,382,0 +sparklymelon,382,0 +shiningmelon,382,0 +gmelon,382,0 +smelon,382,0 +creeperegg,383,50 +eggcreeper,383,50 +skeletonegg,383,51 +eggskeleton,383,51 +spideregg,383,52 +eggspider,383,52 +giantegg,383,53 +egggiant,383,53 +zombieegg,383,54 +eggzombie,383,54 +slimeegg,383,55 +eggslime,383,55 +ghastegg,383,56 +eggghast,383,56 +zombiepigmanegg,383,57 +zpigmanegg,383,57 +pigmanegg,383,57 +zombiepmanegg,383,57 +zpmanegg,383,57 +zombiepigmegg,383,57 +zpigmegg,383,57 +zombiepigegg,383,57 +zpigegg,383,57 +zombiepmegg,383,57 +zombiepegg,383,57 +eggzombiepigman,383,57 +eggzpigman,383,57 +eggpigman,383,57 +eggzombiepman,383,57 +eggzpman,383,57 +eggzombiepigm,383,57 +eggzpigm,383,57 +eggzombiepig,383,57 +eggzpig,383,57 +eggzombiepm,383,57 +eggzombiep,383,57 +endermanegg,383,58 +eggenderman,383,58 +eggcavespider,383,59 +cavespideregg,383,59 +silverfishegg,383,60 +eggsilverfish,383,60 +blazeegg,383,61 +eggblaze,383,61 +lavaslimeegg,383,62 +lavacubeegg,383,62 +magmacubeegg,383,62 +magmaslimeegg,383,62 +egglavaslime,383,62 +egglavacube,383,62 +eggmagmacube,383,62 +eggmagmaslime,383,62 +bategg,383,65 +eggbat,383,65 +witchegg,383,66 +eggwitch,383,66 +pigegg,383,90 +eggpig,383,90 +sheepegg,383,91 +eggsheep,383,91 +cowegg,383,92 +eggcow,383,92 +chickenegg,383,93 +eggchicken,383,93 +squidegg,383,94 +eggsquid,383,94 +wolfegg,383,95 +eggwolf,383,95 +mooshroomegg,383,96 +mushroomcowegg,383,96 +eggmooshroom,383,96 +eggmushroomcow,383,96 +snowgolemegg,383,97 +sgolemegg,383,97 +eggsnowgolem,383,97 +eggsgolem,383,97 +ocelotegg,383,98 +eggocelot,383,98 +irongolemegg,383,99 +igolemegg,383,99 +eggirongolem,383,99 +eggigolem,383,99 +egghorse,383,100 +horseegg,383,100 +villageregg,383,120 +eggvillager,383,120 +bottleofenchanting,384,0 +enchantingbottle,384,0 +expbottle,384,0 +xpbottle,384,0 +bottleexp,384,0 +bottlexp,384,0 +enchantbottle,384,0 +bottleenchanting,384,0 +bottleenchant,384,0 +bottleoenchanting,384,0 +firecharge,385,0 +fireball,385,0 +grenade,385,0 +bookandquill,386,0 +booknquill,386,0 +bookandfeather,386,0 +booknfeather,386,0 +writeablebook,386,0 +writtenbook,387,0 +readablebook,387,0 +sealedbook,387,0 +diary,387,0 +ownedbook,387,0 +emerald,388,0 +itemframe,389,0 +pictureframe,389,0 +iframe,389,0 +pframe,389,0 +flowerpot,390,0 +pot,390,0 +carrot,391,0 +potato,392,0 +rawpotato,392,0 +bakedpotato,393,0 +roastedpotato,393,0 +cookedpotato,393,0 +bakepotato,393,0 +roastpotato,393,0 +cookpotato,393,0 +bpotato,393,0 +rpotato,393,0 +cpotato,393,0 +poisonouspotato,394,0 +poisonpotato,394,0 +ppotato,394,0 +emptymap,395,0 +map,395,0 +goldencarrot,396,0 +goldcarrot,396,0 +gcarrot,396,0 +head,397,0 +skull,397,0 +skeletonhead,397,0 +headskeleton,397,0 +skeletonskull,397,0 +skullskeleton,397,0 +witherhead,397,1 +witherskeletonhead,397,1 +wskeletionhead,397,1 +headwither,397,1 +headwitherskeleton,397,1 +headwskeletion,397,1 +witherskull,397,1 +witherskeletonskull,397,1 +wskeletionskull,397,1 +skullwither,397,1 +skullwitherskeleton,397,1 +skullwskeletion,397,1 +zombiehead,397,2 +headzombie,397,2 +zombieskull,397,2 +skullzombie,397,2 +playerhead,397,3 +humanhead,397,3 +stevehead,397,3 +headplayer,397,3 +headhuman,397,3 +headsteve,397,3 +playerskull,397,3 +humanskull,397,3 +steveskull,397,3 +skullplayer,397,3 +skullhuman,397,3 +skullsteve,397,3 +creeperhead,397,4 +headcreeper,397,4 +creeperskull,397,4 +skullcreeper,397,4 +carrotonastick,398,0 +carrotonstick,398,0 +netherstar,399,0 +hellstar,399,0 +nstar,399,0 +hstar,399,0 +star,399,0 +pumpkinpie,400,0 +pumpkincake,400,0 +ppie,400,0 +pcake,400,0 +pie,400,0 +fireworkrocket,401,0 +fireworkmissle,401,0 +firework,401,0 +fworkrocket,401,0 +fworkmissle,401,0 +fwork,401,0 +fwrocket,401,0 +fwmissle,401,0 +fireworkstar,402,0 +fworkstar,402,0 +fwstar,402,0 +fireworkball,402,0 +fworkball,402,0 +fwball,402,0 +fireworkpowder,402,0 +fworkpowder,402,0 +fwpowder,402,0 +fireworkcharge,402,0 +fworkcharge,402,0 +fwcharge,402,0 +enchantedbook,403,0 +enchantmentbook,403,0 +enchantingbook,403,0 +enchantbook,403,0 +magicalbook,403,0 +magicbook,403,0 +ebook,403,0 +mbook,403,0 +redstonecomparator,404,0 +redstonecomparer,404,0 +redstonecompare,404,0 +rstonecomparator,404,0 +rstonecomparer,404,0 +rstonecompare,404,0 +redscomparator,404,0 +redscomparer,404,0 +redscompare,404,0 +rscomparator,404,0 +rscomparer,404,0 +rscompare,404,0 +comparator,404,0 +comparer,404,0 +compare,404,0 +netherbrick,405,0 +nbrick,405,0 +hellbrick,405,0 +deathbrick,405,0 +dbrick,405,0 +hbrick,405,0 +netherquartz,406,0 +deathquartz,406,0 +hellquartz,406,0 +nquartz,406,0 +dquartz,406,0 +hquartz,406,0 +quartz,406,0 +tntminecart,407,0 +dynamiteminecart,407,0 +dynamitemcart,407,0 +dynamitecart,407,0 +bombminecart,407,0 +bombmcart,407,0 +bombcart,407,0 +tntmcart,407,0 +tntcart,407,0 +dminecart,407,0 +dmcart,407,0 +dcart,407,0 +bminecart,407,0 +bmcart,407,0 +bcart,407,0 +tminecart,407,0 +tmcart,407,0 +tcart,407,0 +hopperminecart,408,0 +hoppermcart,408,0 +hoppercart,408,0 +hopminecart,408,0 +hopmcart,408,0 +hopcart,408,0 +hminecart,408,0 +hmcart,408,0 +hcart,408,0 +ironhorsearmor,417,0 +ironharmor,417,0 +ironarmor,417,0 +ihorsearmor,417,0 +iharmor,417,0 +iarmor,417,0 +steelhorsearmor,417,0 +steelharmor,417,0 +steelarmor,417,0 +shorsearmor,417,0 +sharmor,417,0 +sarmor,417,0 +goldenhorsearmor,418,0 +goldenharmor,418,0 +goldenarmor,418,0 +goldhorsearmor,418,0 +goldharmor,418,0 +goldarmor,418,0 +ghorsearmor,418,0 +gharmor,418,0 +garmor,418,0 +diamondhorsearmor,419,0 +diamondharmor,419,0 +diamondarmor,419,0 +dhorsearmor,419,0 +dharmor,419,0 +darmor,419,0 +crystalhorsearmor,419,0 +crystalharmor,419,0 +crystalarmor,419,0 +chorsearmor,419,0 +charmor,419,0 +carmor,419,0 +lead,420,0 +leash,420,0 +rope,420,0 +nametag,421,0 +tag,421,0 +commandblockminecart,422,0 +cmdblockminecart,422,0 +cblockminecart,422,0 +commandminecart,422,0 +cmdminecart,422,0 +cbminecart,422,0 +commandblockcart,422,0 +cmdblockcart,422,0 +cblockcart,422,0 +commandcart,422,0 +cmdcart,422,0 +cbcart,422,0 +13disc,2256,0 +goldmusicrecord,2256,0 +goldmusicdisk,2256,0 +goldmusicdisc,2256,0 +goldmusiccd,2256,0 +13musicrecord,2256,0 +13musicdisk,2256,0 +13musicdisc,2256,0 +13musiccd,2256,0 +gomusicrecord,2256,0 +gomusicdisk,2256,0 +gomusicdisc,2256,0 +gomusiccd,2256,0 +goldmrecord,2256,0 +goldmdisk,2256,0 +goldmdisc,2256,0 +goldmcd,2256,0 +13mrecord,2256,0 +13mdisk,2256,0 +13mdisc,2256,0 +13mcd,2256,0 +gomrecord,2256,0 +gomdisk,2256,0 +gomdisc,2256,0 +gomcd,2256,0 +goldrecord,2256,0 +golddisk,2256,0 +golddisc,2256,0 +goldcd,2256,0 +13record,2256,0 +13disk,2256,0 +13cd,2256,0 +gorecord,2256,0 +godisk,2256,0 +godisc,2256,0 +gocd,2256,0 +record1,2256,0 +disk1,2256,0 +disc1,2256,0 +cd1,2256,0 +1record,2256,0 +1disk,2256,0 +1disc,2256,0 +1cd,2256,0 +catdisc,2257,0 +greenmusicrecord,2257,0 +greenmusicdisk,2257,0 +greenmusicdisc,2257,0 +greenmusiccd,2257,0 +catmusicrecord,2257,0 +catmusicdisk,2257,0 +catmusicdisc,2257,0 +catmusiccd,2257,0 +grmusicrecord,2257,0 +grmusicdisk,2257,0 +grmusicdisc,2257,0 +grmusiccd,2257,0 +greenmrecord,2257,0 +greenmdisk,2257,0 +greenmdisc,2257,0 +greenmcd,2257,0 +catmrecord,2257,0 +catmdisk,2257,0 +catmdisc,2257,0 +catmcd,2257,0 +grmrecord,2257,0 +grmdisk,2257,0 +grmdisc,2257,0 +grmcd,2257,0 +greenrecord,2257,0 +greendisk,2257,0 +greendisc,2257,0 +greencd,2257,0 +catrecord,2257,0 +catdisk,2257,0 +catcd,2257,0 +grrecord,2257,0 +grdisk,2257,0 +grdisc,2257,0 +grcd,2257,0 +record2,2257,0 +disk2,2257,0 +disc2,2257,0 +cd2,2257,0 +2record,2257,0 +2disk,2257,0 +2disc,2257,0 +2cd,2257,0 +blocksdisc,2258,0 +orangemusicrecord,2258,0 +orangemusicdisk,2258,0 +orangemusicdisc,2258,0 +orangemusiccd,2258,0 +blocksmusicrecord,2258,0 +blocksmusicdisk,2258,0 +blocksmusicdisc,2258,0 +blocksmusiccd,2258,0 +ormusicrecord,2258,0 +ormusicdisk,2258,0 +ormusicdisc,2258,0 +ormusiccd,2258,0 +orangemrecord,2258,0 +orangemdisk,2258,0 +orangemdisc,2258,0 +orangemcd,2258,0 +blocksmrecord,2258,0 +blocksmdisk,2258,0 +blocksmdisc,2258,0 +blocksmcd,2258,0 +ormrecord,2258,0 +ormdisk,2258,0 +ormdisc,2258,0 +ormcd,2258,0 +orangerecord,2258,0 +orangedisk,2258,0 +orangedisc,2258,0 +orangecd,2258,0 +blocksrecord,2258,0 +blocksdisk,2258,0 +blockscd,2258,0 +orrecord,2258,0 +ordisk,2258,0 +ordisc,2258,0 +orcd,2258,0 +record3,2258,0 +disk3,2258,0 +disc3,2258,0 +cd3,2258,0 +3record,2258,0 +3disk,2258,0 +3disc,2258,0 +3cd,2258,0 +chirpdisc,2259,0 +redmusicrecord,2259,0 +redmusicdisk,2259,0 +redmusicdisc,2259,0 +redmusiccd,2259,0 +chirpmusicrecord,2259,0 +chirpmusicdisk,2259,0 +chirpmusicdisc,2259,0 +chirpmusiccd,2259,0 +remusicrecord,2259,0 +remusicdisk,2259,0 +remusicdisc,2259,0 +remusiccd,2259,0 +redmrecord,2259,0 +redmdisk,2259,0 +redmdisc,2259,0 +redmcd,2259,0 +chirpmrecord,2259,0 +chirpmdisk,2259,0 +chirpmdisc,2259,0 +chirpmcd,2259,0 +remrecord,2259,0 +remdisk,2259,0 +remdisc,2259,0 +remcd,2259,0 +redrecord,2259,0 +reddisk,2259,0 +reddisc,2259,0 +redcd,2259,0 +chirprecord,2259,0 +chirpdisk,2259,0 +chirpcd,2259,0 +rerecord,2259,0 +redisk,2259,0 +redisc,2259,0 +recd,2259,0 +record4,2259,0 +disk4,2259,0 +disc4,2259,0 +cd4,2259,0 +4record,2259,0 +4disk,2259,0 +4disc,2259,0 +4cd,2259,0 +fardisc,2260,0 +lightgreenmusicrecord,2260,0 +lightgreenmusicdisk,2260,0 +lightgreenmusicdisc,2260,0 +lightgreenmusiccd,2260,0 +lgreenmusicrecord,2260,0 +lgreenmusicdisk,2260,0 +lgreenmusicdisc,2260,0 +lgreenmusiccd,2260,0 +lightgrmusicrecord,2260,0 +lightgrmusicdisk,2260,0 +lightgrmusicdisc,2260,0 +lightgrmusiccd,2260,0 +farmusicrecord,2260,0 +farmusicdisk,2260,0 +farmusicdisc,2260,0 +farmusiccd,2260,0 +lgrmusicrecord,2260,0 +lgrmusicdisk,2260,0 +lgrmusicdisc,2260,0 +lgrmusiccd,2260,0 +lightgreenmrecord,2260,0 +lightgreenmdisk,2260,0 +lightgreenmdisc,2260,0 +lightgreenmcd,2260,0 +lgreenmrecord,2260,0 +lgreenmdisk,2260,0 +lgreenmdisc,2260,0 +lgreenmcd,2260,0 +lightgrmrecord,2260,0 +lightgrmdisk,2260,0 +lightgrmdisc,2260,0 +lightgrmcd,2260,0 +farmrecord,2260,0 +farmdisk,2260,0 +farmdisc,2260,0 +farmcd,2260,0 +lgrmrecord,2260,0 +lgrmdisk,2260,0 +lgrmdisc,2260,0 +lgrmcd,2260,0 +lightgreenrecord,2260,0 +lightgreendisk,2260,0 +lightgreendisc,2260,0 +lightgreencd,2260,0 +lgreenrecord,2260,0 +lgreendisk,2260,0 +lgreendisc,2260,0 +lgreencd,2260,0 +lightgrrecord,2260,0 +lightgrdisk,2260,0 +lightgrdisc,2260,0 +lightgrcd,2260,0 +farrecord,2260,0 +fardisk,2260,0 +farcd,2260,0 +lgrrecord,2260,0 +lgrdisk,2260,0 +lgrdisc,2260,0 +lgrcd,2260,0 +record5,2260,0 +disk5,2260,0 +disc5,2260,0 +cd5,2260,0 +5record,2260,0 +5disk,2260,0 +5disc,2260,0 +5cd,2260,0 +malldisc,2261,0 +purplemusicrecord,2261,0 +purplemusicdisk,2261,0 +purplemusicdisc,2261,0 +purplemusiccd,2261,0 +mallmusicrecord,2261,0 +mallmusicdisk,2261,0 +mallmusicdisc,2261,0 +mallmusiccd,2261,0 +pumusicrecord,2261,0 +pumusicdisk,2261,0 +pumusicdisc,2261,0 +pumusiccd,2261,0 +purplemrecord,2261,0 +purplemdisk,2261,0 +purplemdisc,2261,0 +purplemcd,2261,0 +mallmrecord,2261,0 +mallmdisk,2261,0 +mallmdisc,2261,0 +mallmcd,2261,0 +pumrecord,2261,0 +pumdisk,2261,0 +pumdisc,2261,0 +pumcd,2261,0 +purplerecord,2261,0 +purpledisk,2261,0 +purpledisc,2261,0 +purplecd,2261,0 +mallrecord,2261,0 +malldisk,2261,0 +mallcd,2261,0 +purecord,2261,0 +pudisk,2261,0 +pudisc,2261,0 +pucd,2261,0 +record6,2261,0 +disk6,2261,0 +disc6,2261,0 +cd6,2261,0 +6record,2261,0 +6disk,2261,0 +6disc,2261,0 +6cd,2261,0 +mellohidisc,2262,0 +pinkmusicrecord,2262,0 +pinkmusicdisk,2262,0 +pinkmusicdisc,2262,0 +pinkmusiccd,2262,0 +mellohimusicrecord,2262,0 +mellohimusicdisk,2262,0 +mellohimusicdisc,2262,0 +mellohimusiccd,2262,0 +pimusicrecord,2262,0 +pimusicdisk,2262,0 +pimusicdisc,2262,0 +pimusiccd,2262,0 +pinkmrecord,2262,0 +pinkmdisk,2262,0 +pinkmdisc,2262,0 +pinkmcd,2262,0 +mellohimrecord,2262,0 +mellohimdisk,2262,0 +mellohimdisc,2262,0 +mellohimcd,2262,0 +pimrecord,2262,0 +pimdisk,2262,0 +pimdisc,2262,0 +pimcd,2262,0 +pinkrecord,2262,0 +pinkdisk,2262,0 +pinkdisc,2262,0 +pinkcd,2262,0 +mellohirecord,2262,0 +mellohidisk,2262,0 +mellohicd,2262,0 +pirecord,2262,0 +pidisk,2262,0 +pidisc,2262,0 +picd,2262,0 +record7,2262,0 +disk7,2262,0 +disc7,2262,0 +cd7,2262,0 +7record,2262,0 +7disk,2262,0 +7disc,2262,0 +7cd,2262,0 +staldisc,2263,0 +blackmusicrecord,2263,0 +blackmusicdisk,2263,0 +blackmusicdisc,2263,0 +blackmusiccd,2263,0 +stalmusicrecord,2263,0 +stalmusicdisk,2263,0 +stalmusicdisc,2263,0 +stalmusiccd,2263,0 +blmusicrecord,2263,0 +blmusicdisk,2263,0 +blmusicdisc,2263,0 +blmusiccd,2263,0 +blackmrecord,2263,0 +blackmdisk,2263,0 +blackmdisc,2263,0 +blackmcd,2263,0 +stalmrecord,2263,0 +stalmdisk,2263,0 +stalmdisc,2263,0 +stalmcd,2263,0 +blmrecord,2263,0 +blmdisk,2263,0 +blmdisc,2263,0 +blmcd,2263,0 +blackrecord,2263,0 +blackdisk,2263,0 +blackdisc,2263,0 +blackcd,2263,0 +stalrecord,2263,0 +staldisk,2263,0 +stalcd,2263,0 +blrecord,2263,0 +bldisk,2263,0 +bldisc,2263,0 +blcd,2263,0 +record8,2263,0 +disk8,2263,0 +disc8,2263,0 +cd8,2263,0 +8record,2263,0 +8disk,2263,0 +8disc,2263,0 +8cd,2263,0 +straddisc,2264,0 +whitemusicrecord,2264,0 +whitemusicdisk,2264,0 +whitemusicdisc,2264,0 +whitemusiccd,2264,0 +stradmusicrecord,2264,0 +stradmusicdisk,2264,0 +stradmusicdisc,2264,0 +stradmusiccd,2264,0 +whmusicrecord,2264,0 +whmusicdisk,2264,0 +whmusicdisc,2264,0 +whmusiccd,2264,0 +whitemrecord,2264,0 +whitemdisk,2264,0 +whitemdisc,2264,0 +whitemcd,2264,0 +stradmrecord,2264,0 +stradmdisk,2264,0 +stradmdisc,2264,0 +stradmcd,2264,0 +whmrecord,2264,0 +whmdisk,2264,0 +whmdisc,2264,0 +whmcd,2264,0 +whiterecord,2264,0 +whitedisk,2264,0 +whitedisc,2264,0 +whitecd,2264,0 +stradrecord,2264,0 +straddisk,2264,0 +stradcd,2264,0 +whrecord,2264,0 +whdisk,2264,0 +whdisc,2264,0 +whcd,2264,0 +record9,2264,0 +disk9,2264,0 +disc9,2264,0 +cd9,2264,0 +9record,2264,0 +9disk,2264,0 +9disc,2264,0 +9cd,2264,0 +warddisc,2265,0 +darkgreenmusicrecord,2265,0 +darkgreenmusicdisk,2265,0 +darkgreenmusicdisc,2265,0 +darkgreenmusiccd,2265,0 +dgreenmusicrecord,2265,0 +dgreenmusicdisk,2265,0 +dgreenmusicdisc,2265,0 +dgreenmusiccd,2265,0 +darkgrmusicrecord,2265,0 +darkgrmusicdisk,2265,0 +darkgrmusicdisc,2265,0 +darkgrmusiccd,2265,0 +wardmusicrecord,2265,0 +wardmusicdisk,2265,0 +wardmusicdisc,2265,0 +wardmusiccd,2265,0 +dgrmusicrecord,2265,0 +dgrmusicdisk,2265,0 +dgrmusicdisc,2265,0 +dgrmusiccd,2265,0 +darkgreenmrecord,2265,0 +darkgreenmdisk,2265,0 +darkgreenmdisc,2265,0 +darkgreenmcd,2265,0 +dgreenmrecord,2265,0 +dgreenmdisk,2265,0 +dgreenmdisc,2265,0 +dgreenmcd,2265,0 +darkgrmrecord,2265,0 +darkgrmdisk,2265,0 +darkgrmdisc,2265,0 +darkgrmcd,2265,0 +wardmrecord,2265,0 +wardmdisk,2265,0 +wardmdisc,2265,0 +wardmcd,2265,0 +dgrmrecord,2265,0 +dgrmdisk,2265,0 +dgrmdisc,2265,0 +dgrmcd,2265,0 +darkgreenrecord,2265,0 +darkgreendisk,2265,0 +darkgreendisc,2265,0 +darkgreencd,2265,0 +dgreenrecord,2265,0 +dgreendisk,2265,0 +dgreendisc,2265,0 +dgreencd,2265,0 +darkgrrecord,2265,0 +darkgrdisk,2265,0 +darkgrdisc,2265,0 +darkgrcd,2265,0 +wardrecord,2265,0 +warddisk,2265,0 +wardcd,2265,0 +dgrrecord,2265,0 +dgrdisk,2265,0 +dgrdisc,2265,0 +dgrcd,2265,0 +record10,2265,0 +disk10,2265,0 +disc10,2265,0 +cd10,2265,0 +10record,2265,0 +10disk,2265,0 +10disc,2265,0 +10cd,2265,0 +11disc,2266,0 +crackedmusicrecord,2266,0 +crackedmusicdisk,2266,0 +crackedmusicdisc,2266,0 +crackedmusiccd,2266,0 +crackmusicrecord,2266,0 +crackmusicdisk,2266,0 +crackmusicdisc,2266,0 +crackmusiccd,2266,0 +11musicrecord,2266,0 +11musicdisk,2266,0 +11musicdisc,2266,0 +11musiccd,2266,0 +cmusicrecord,2266,0 +cmusicdisk,2266,0 +cmusicdisc,2266,0 +cmusiccd,2266,0 +crackedmrecord,2266,0 +crackedmdisk,2266,0 +crackedmdisc,2266,0 +crackedmcd,2266,0 +crackmrecord,2266,0 +crackmdisk,2266,0 +crackmdisc,2266,0 +crackmcd,2266,0 +11mrecord,2266,0 +11mdisk,2266,0 +11mdisc,2266,0 +11mcd,2266,0 +cmrecord,2266,0 +cmdisk,2266,0 +cmdisc,2266,0 +cmcd,2266,0 +crackedrecord,2266,0 +crackeddisk,2266,0 +crackeddisc,2266,0 +crackedcd,2266,0 +crackrecord,2266,0 +crackdisk,2266,0 +crackdisc,2266,0 +crackcd,2266,0 +crecord,2266,0 +cdisk,2266,0 +cdisc,2266,0 +ccd,2266,0 +record11,2266,0 +disk11,2266,0 +disc11,2266,0 +cd11,2266,0 +11record,2266,0 +11disk,2266,0 +11cd,2266,0 +waitdisc,2267,0 +waitmusicrecord,2267,0 +waitmusicdisk,2267,0 +waitmusicdisc,2267,0 +waitmusiccd,2267,0 +bluemusicrecord,2267,0 +bluemusicdisk,2267,0 +bluemusicdisc,2267,0 +bluemusiccd,2267,0 +12musicrecord,2267,0 +12musicdisk,2267,0 +12musicdisc,2267,0 +12musiccd,2267,0 +cyanmusicrecord,2267,0 +cyanmusicdisk,2267,0 +cyanmusicdisc,2267,0 +cyanmusiccd,2267,0 +waitmrecord,2267,0 +waitmdisk,2267,0 +waitmdisc,2267,0 +waitmcd,2267,0 +bluemrecord,2267,0 +bluemdisk,2267,0 +bluemdisc,2267,0 +bluemcd,2267,0 +12mrecord,2267,0 +12mdisk,2267,0 +12mdisc,2267,0 +12mcd,2267,0 +cyanmrecord,2267,0 +cyanmdisk,2267,0 +cyanmdisc,2267,0 +cyanmcd,2267,0 +waitrecord,2267,0 +waitdisk,2267,0 +waitcd,2267,0 +bluerecord,2267,0 +bluedisk,2267,0 +bluedisc,2267,0 +bluecd,2267,0 +cyanrecord,2267,0 +cyandisk,2267,0 +cyandisc,2267,0 +cyancd,2267,0 +record12,2267,0 +disk12,2267,0 +disc12,2267,0 +cd12,2267,0 +12record,2267,0 +12disk,2267,0 +12disc,2267,0 +12cd,2267,0 +#9024e88d64262f1c5ea92df8399fa658 \ No newline at end of file diff --git a/lives.yml b/lives.yml new file mode 100644 index 0000000..04ec367 --- /dev/null +++ b/lives.yml @@ -0,0 +1 @@ +lives: {} diff --git a/locale.yml b/locale.yml new file mode 100644 index 0000000..619f9fe --- /dev/null +++ b/locale.yml @@ -0,0 +1,107 @@ +player_only: "&cOnly players may use that!" +no_permission: "&cNo permission." +player_unfound: "&e{0}&4 could not be found" +enabled: "&aEnabled" +disabled: "&cDisabled" +able: "&aAble" +unable: "&cUnable" +inventoryFull: "&cYou must clear your inventory first!" +notNumber: "&e{0} is not a number!" +angle_message: "&e{0} yaw&f, &e{1} pitch" +revive_cooldown: "&4You may not revive a player for another &e{0}4." +not_dead: "&e{0} &eis not deathbanned" +revived: "&aYou have revived &e{0}&a!" +revive_player: "&cYou revived {0}!" +revive_broadcast: "&c{0} revived {1}!" +selectEndPortal: "&cYou must select an end portal frame!" +locationSuccess: "&aSet location {0}" +firstLocationUnset: "&cYou must set the first location!" +portalTooBig: "&cYou cannot create a portal that big!" +portalElevation: "&cMake sure the portal is on the same elevation!" +portalSuccess: "&aCreated portal." +portalWandGive: "&aSelect 2 points to make an end portal" +noCooldown: "&4You do not have a Gopple cooldown active." +activeCooldown: "&eYour Gopple cooldown expires in {0}" +helpMenu: + - "&aThis is" + - "&aThe help menu" +userLocation: "&e{0}&a is in the area of {1} at coordinates: {2},{3},{4}" +logoutActive: "&aYour logout timer is already active!" +logoutStart: "&aYour logout timer is now active!" +pvpTimerNotActive: "&cYour {0} timer is currently not active." +pvpTimerDeactivate: "&cYour {0} timer has now been deactivated!" +pvpTimerActive: "&aYour {0} timer is still active for another {1}" +notInFaction: "&cYou are not in a faction!" +fullDTR: "&aYour faction has full DTR." +frozenDTR: "&aYour faction DTR is frozen for another {0}" +regeneratingDTR: "&aYour faction currently has {0} DTR and is regenerating at a rate of {1} every {2}. Estimated time until full DTR is {3}." +serverTime: "&aThe server time is {0}" +cannonOnlyOverworld: "&aYou can only " +toggleCapZoneMessages: "&eYou are now {0} to see cap zone entry messages" +toggleFDMessages: "&e{0} &ahas toggled &bFound Diamond Alerts" +toggleLSMessages: "&eYou will now be {0} to see Lightning Strikes on player deaths" + +# Scoreboard toggle +toggleScoreboard: "&eYou have now {0} your scoreboard" + +# Lives and deathban messages +noLivesInDB: "&eThere are no lives in the database!" +eotwDeathBanJoin: "&cYou are deathbanned for the rest of the map due to EOTW." +deathbanTimer: "&cYou are still deathbanned for {0}" +lifeUsed: "&aYou have used a life! You now have {0} lives." +noLives: "&cYou have no lives!" +deathbanWithLives: "&cYou are still deathbanned with {0} remaining! You can use a life by joining within {1}" +deathbanBypass: "&aYou would be deathbanned, but you have permission to bypass." +playerLifeCheck: "&e{0} currently has {1} lives" +notDeathbanned: "&e{0} is not deathbanned!" +deathbanReason: + - "&eDeathban caused by {0}" + - "&eTime: {1}" + - "&eDuration: {2}" +deathbanLocation: "&eLocation: ({0},{1},{2})" +deathbanReason: "&eReason: [{0}]" +clearDeathbanMessaage: "&eAll deathbans have been cleared" +livesMustBePositive: "&cThe amount of lives must be positive" +livesGiftFailure: "&cYou could not give {0} {1} live(s) because you only have {2}." +livesGiftSuccess: "&aYou gifted {0} with {1} live(s)" +livesGiftSuccessPlayer: "&e{0} gifted you with {1} live(s)" +livesReviveKitmap: "&eYou cannot revive players during kitmap!" +livesReviveEOTW: "&eYou cannot revive players during EOTW!" +lifeUsedOnOther: "&eYou have used a life to revive {0}" +livesConsoleRevive: "&eYou have revived {0}" +livesSet: "&e{0} now has {1} lives." +deathbanDurationError: "&cInvalid duration! Use format &o1h 2m" +deathbanDurationSet: "&eDeathban time has now been set to {0}!" +topLivesTitle: "&eTop {0} lives:" +topLivesFormat: "&e{0} {1}: {2}" +ecoGiveAll: "&e{0} gave all players ${1}" +ecoBalance: "&eYour balance: {0}" +ecoBalanceOther: "&e{0}'s balance: {1}" +ecoAdded: "&eAdded {0} to {1}'s balance. Their new balance is {2}" +ecoTaken: "&eTaken {0} from {1}'s balance. Their new balance is {2}" +ecoSet: "&eSet balance of {0} to {1}" +ecoNotPositive: "&cYou must send money in positive amounts." +ecoSendFailure: "&cYou tried to pay {0}, but you only have {1} in your account." +ecoSendSuccess: "&aYou have sent {0} to {1}" +ecoSendSuccessPlayer: "&a{0} sent you {1}" +notPlayerFaction: "&cThat faction could not be found or is not a player faction." +noEvents: "&cThere are no running events!" +eventCancelled: "&c{0} has cancelled the event {1}" +eventCreateNameUsed: "&cThere is already an event faction named {0}" +eventCreateSuccess: "&aCreated event faction {0} with event type {1}!" +eventDeleteNameUnused: "&cThere is no such event faction called {0}" +eventDeleteSuccess: "&aDeleted event faction {0}!" +eventRenameSuccess: "&aRenamed event {0} to {1}" +noWorldEdit: "&cYou need WorldEdit installed to use this feature!" +requireWorldEditSelection: "&cPlease make a WorldEdit selection!" +areaTooSmall: "&cRegion selection must be {0} x {0}" +eventAreaSuccess: "&aUpdated the claim area for event {0}" +eventStarted: "&aEvent has been started!" +eventUptime: "&aEvent &e({0})&a has been live for &e{1}&a and started at &e{2}" +conquestSetPointsError: "&cMaximum points for Conquest is {0}" +conquestSetPoints: "&aSet points for {0} to {1}" +noKeyFound: "&cNo key type named {0}" +keyOnlyPositive: "&cYou can only give keys in positive quantities" +keyMaximumAllowed: "&cYou cannot give keys in more than {0}'s" +keyGiven: "&cGiven {0}x {1} key to {2}" +crateClosedDuring: "&aYou closed your crate reward inventory, dropping your items on the ground!" \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..67eb09f --- /dev/null +++ b/plugin.yml @@ -0,0 +1,130 @@ +name: Zorex +version: 1.0 +description: HCF CORE +author: bruceboy +main: me.bruce.factions.LorexHCF +softdepend: [ProtocolLib] +commands: + hcf: + rawcast: + wb: + nv: + stats: + setnpc: + staffguide: + tablistgui: + aliases: [tabgui] + coords: + pots: + vanish: + aliases: [v] + staffgui: + author: + aliases: [dev,developer,best,bestdev] + gamemode: + aliases: [gm] + setprefix: + slowchat: + disablechat: + tp: + here: + fly: + fix: + invsee: + randomtp: + panic: + tl: + baller: + rules: + vip: + zorex: + spawn: + lff: + pro: + prefix: + keysale: + sp: + fr: + reboot: + rank: + broadcast: + aliases: [bc] + buy: + tablist: + aliases: [pot] + settings: + refund: + aliases: [inv, restore, invrestore] + ping: + freeze: + aliases: [ss] + enderdragon: + hub: + this: + playtime: + aliases: [pt] + cobble: + crowgive: + aliases: [crowbar, crowbargive] + Amethyst: + hcfhelp: + aliases: [help, ehelp, pl, ?] + conquest: + description: Command used to handle Conquest events. + economy: + aliases: [$, bal, money, eco, econ] + description: Command used to modify the economy. + eotw: + aliases: [endoftheworld] + description: Sets if the server is in End of the World mode. + event: + description: Command used to manage minigame events. + faction: + aliases: [f, fac] + description: Faction related commands. + gopple: + description: Command to check remaining OP apple cooldown time. + aliases: [opple, goppletimer, goppletime, oppletimer, oppletime] + hcf: + aliases: [hardcorefactions, hcfactions] + koth: + description: Make or delete KotH arenas. + lives: + description: Management of lives or deathbans. + location: + aliases: [loc] + description: Check the faction location of a player. + logout: + aliases: [disconnect] + description: Command to safely logout without an NPC spawning. + mapkit: + aliases: [viewkit] + description: Used to check the current map restrictions. + pay: + aliases: [p2p] + description: Allow players to pay money. + pvptimer: + aliases: [pvp] + description: Command to enable or disable pvp timer protection. + regen: + description: Check ETA until a faction is able to regenerate DTR. + sotw: + aliases: [startoftheworld] + description: Command used to manage start of the world. + staffrevive: + aliases: [revive] + description: Command used by staff to revive players. + timer: + description: Command to manage timers. + togglecapzoneentry: + aliases: [togglecapentry] + description: Command used to hide or show capture zone entry messages. + togglelightning: + aliases: [lightningtoggle, togglestrikes] + description: Toggles the lightning strikes for when a player dies. + rename: + ores: + description: See ores mined. + aliases: [stats, mined] + glowstonemountain: + aliases: [reset] \ No newline at end of file diff --git a/settings.yml b/settings.yml new file mode 100644 index 0000000..4bb0deb --- /dev/null +++ b/settings.yml @@ -0,0 +1,75 @@ +disable_obsidian_generators: true +server_time_zone: EST +warzone_radius: 650 +donate_url: store.Vengeful.us +spawn_buffer: 128 +map_number: 1 +disallowed_faction_names: +- Venge +- Vengeful +enchantment_limits: + PROTECTION_ENVIRONMENTAL: 2 + DAMAGE_ALL: 1 + ARROW_KNOCKBACK: 0 + KNOCKBACK: 0 + FIRE_ASPECT: 0 + THORNS: 0 + ARROW_FIRE: 1 + ARROW_DAMAGE: 3 +potion_limits: + STRENGTH: 1 + WEAKNESS: 0 + SLOWNESS: 0 + INVISIBILITY: 0 + POISON: 0 +road_lengths: + NORMAL: 4000 + NETHER: 4000 +border_sizes: + NORMAL: 2000 + NETHER: 2000 + THE_END: 1500 +spawn_radius_map: + NORMAL: 50 + NETHER: 25 + THE_END: 15 +diamond_ore_alerts: false +subclaim_name_characters_min: 3 +subclaim_name_characters_max: 16 +faction_name_characters_min: 3 +faction_name_characters_max: 16 +max_members_per_faction: 8 +road_distance: 2500 +road_min_height: 0 +road_max_height: 256 +end_portal_radius: 20 +end_portal_center: 750 +default_deathban_duration: 3600000 +kit_map: true +#Tablist is currently weird for 1.8 users use if you want +tablist: false +teammate_colour: DARK_GREEN +ally_colour: LIGHT_PURPLE +enemy_colour: RED +safezone_colour: AQUA +road_colour: GOLD +warzone_colour: RED +wilderness_colour: GREEN +scoreboard_title: '(Speed)' +max_allies_per_faction: 0 +max_claims_per_faction: 8 +allow_claiming_besides_roads: false +dtr_millis_between_updates: 45000 +dtr_increment_between_updates: 0.1 +maximum_dtr: 6.0 +exp_multiplier_general: 2.0 +exp_multiplier_fishing: 2.0 +exp_multiplier_smelting: 2.0 +exp_multiplier_looting_per_level: 6.0 +exp_multiplier_luck_per_level: 1.5 +exp_multiplier_fortune_per_level: 1.5 +conquest_point_loss_per_death: 30 +conquest_required_win_points: 300 +found_diamonds_alerts: true +combat_log_despawn_ticks: 600 +combat_log_prevention_enabled: true diff --git a/src/LorexMC/us/utils/BukkitUtils.java b/src/LorexMC/us/utils/BukkitUtils.java new file mode 100644 index 0000000..5d7f493 --- /dev/null +++ b/src/LorexMC/us/utils/BukkitUtils.java @@ -0,0 +1,181 @@ +package LorexMC.us.utils; + +import com.google.common.collect.*; + +import gnu.trove.list.*; + +import java.util.stream.*; + +import org.bukkit.command.*; +import org.bukkit.craftbukkit.v1_7_R4.entity.*; + +import net.minecraft.server.v1_7_R4.*; + +import org.bukkit.event.entity.*; +import org.bukkit.projectiles.*; +import org.bukkit.*; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.potion.*; +import org.bukkit.entity.*; +import org.bukkit.entity.Entity; + +import java.util.*; + +import com.google.common.base.*; + +import gnu.trove.list.array.*; + +public final class BukkitUtils { + private static final ImmutableMap CHAT_DYE_COLOUR_MAP; + private static final ImmutableSet DEBUFF_TYPES; + private static final int DEFAULT_COMPLETION_LIMIT = 80; + private static final String STRAIGHT_LINE_TEMPLATE; + public static final String STRAIGHT_LINE_DEFAULT; + private static final TCharList COLOUR_CHARACTER_LIST; + + public static int countColoursUsed(final String id, final boolean ignoreDuplicates) { + int count = 0; + final Set found = new HashSet(); + for (int i = 1; i < id.length(); ++i) { + final char current = id.charAt(i); + if (BukkitUtils.COLOUR_CHARACTER_LIST.contains(current) && id.charAt(i - 1) == '&' + && (ignoreDuplicates || found.add(ChatColor.getByChar(current)))) { + ++count; + } + } + return count; + } + + public static List getCompletions(final String[] args, final List input) { + return getCompletions(args, input, 80); + } + + public static List getCompletions(final String[] args, final List input, final int limit) { + Preconditions.checkNotNull((Object) args); + Preconditions.checkArgument(args.length != 0); + final String argument = args[args.length - 1]; + return input.stream().filter(string -> string.regionMatches(true, 0, argument, 0, argument.length())) + .limit(limit).collect(Collectors.toList()); + } + + public static String getDisplayName(final CommandSender sender) { + Preconditions.checkNotNull((Object) sender); + return (sender instanceof Player) ? ((Player) sender).getDisplayName() : sender.getName(); + } + + public static long getIdleTime(final Player player) { + Preconditions.checkNotNull((Object) player); + final long idleTime = ((CraftPlayer) player).getHandle().x(); + return (idleTime > 0L) ? (MinecraftServer.ar() - idleTime) : 0L; + } + + public static DyeColor toDyeColor(final ChatColor colour) { + return BukkitUtils.CHAT_DYE_COLOUR_MAP.get(colour); + } + + public static Player getFinalAttacker(final EntityDamageEvent ede, final boolean ignoreSelf) { + Player attacker = null; + if (ede instanceof EntityDamageByEntityEvent) { + final EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) ede; + final Entity damager = event.getDamager(); + if (event.getDamager() instanceof Player) { + attacker = (Player) damager; + } else if (event.getDamager() instanceof Projectile) { + final Projectile projectile = (Projectile) damager; + final ProjectileSource shooter = projectile.getShooter(); + if (shooter instanceof Player) { + attacker = (Player) shooter; + } + } + if (attacker != null && ignoreSelf && event.getEntity().equals(attacker)) { + attacker = null; + } + } + return attacker; + } + + public static Player playerWithNameOrUUID(final String string) { + if (string == null) { + return null; + } + return JavaUtils.isUUID(string) ? Bukkit.getPlayer(UUID.fromString(string)) : Bukkit.getPlayer(string); + } + + @Deprecated + public static OfflinePlayer offlinePlayerWithNameOrUUID(final String string) { + if (string == null) { + return null; + } + return JavaUtils.isUUID(string) ? Bukkit.getOfflinePlayer(UUID.fromString(string)) + : Bukkit.getOfflinePlayer(string); + } + + public static boolean isWithinX(final Location location, final Location other, final double distance) { + return location.getWorld().equals(other.getWorld()) && Math.abs(other.getX() - location.getX()) <= distance + && Math.abs(other.getZ() - location.getZ()) <= distance; + } + + public static Location getHighestLocation(final Location origin) { + return getHighestLocation(origin, null); + } + + public static Location getHighestLocation(final Location origin, final Location def) { + Preconditions.checkNotNull((Object) origin, (Object) "The location cannot be null"); + final Location cloned = origin.clone(); + final World world = cloned.getWorld(); + final int x = cloned.getBlockX(); + int y = world.getMaxHeight(); + final int z = cloned.getBlockZ(); + while (y > origin.getBlockY()) { + final Block block = world.getBlockAt(x, --y, z); + if (!block.isEmpty()) { + final Location next = block.getLocation(); + next.setPitch(origin.getPitch()); + next.setYaw(origin.getYaw()); + return next; + } + } + return def; + } + + public static boolean isDebuff(final PotionEffectType type) { + return BukkitUtils.DEBUFF_TYPES.contains(type); + } + + public static boolean isDebuff(final PotionEffect potionEffect) { + return isDebuff(potionEffect.getType()); + } + + public static boolean isDebuff(final ThrownPotion thrownPotion) { + for (final PotionEffect effect : thrownPotion.getEffects()) { + if (isDebuff(effect)) { + return true; + } + } + return false; + } + + static { + STRAIGHT_LINE_TEMPLATE = ChatColor.STRIKETHROUGH.toString() + Strings.repeat("-", 256); + STRAIGHT_LINE_DEFAULT = BukkitUtils.STRAIGHT_LINE_TEMPLATE.substring(0, 55); + CHAT_DYE_COLOUR_MAP = ImmutableMap.builder().put(ChatColor.AQUA, DyeColor.LIGHT_BLUE) + .put(ChatColor.BLACK, DyeColor.BLACK).put(ChatColor.BLUE, DyeColor.LIGHT_BLUE) + .put(ChatColor.DARK_AQUA, DyeColor.CYAN).put(ChatColor.DARK_BLUE, DyeColor.BLUE) + .put(ChatColor.DARK_GRAY, DyeColor.GRAY).put(ChatColor.DARK_GREEN, DyeColor.GREEN) + .put(ChatColor.DARK_PURPLE, DyeColor.PURPLE).put(ChatColor.DARK_RED, DyeColor.RED) + .put(ChatColor.GOLD, DyeColor.ORANGE).put(ChatColor.GRAY, DyeColor.SILVER) + .put(ChatColor.GREEN, DyeColor.LIME).put(ChatColor.LIGHT_PURPLE, DyeColor.MAGENTA) + .put(ChatColor.RED, DyeColor.RED).put(ChatColor.WHITE, DyeColor.WHITE) + .put(ChatColor.YELLOW, DyeColor.YELLOW).build(); + DEBUFF_TYPES = ImmutableSet.builder().add(PotionEffectType.BLINDNESS) + .add(PotionEffectType.CONFUSION).add(PotionEffectType.HARM).add(PotionEffectType.HUNGER) + .add(PotionEffectType.POISON).add(PotionEffectType.SATURATION).add(PotionEffectType.SLOW) + .add(PotionEffectType.SLOW_DIGGING).add(PotionEffectType.WEAKNESS).add(PotionEffectType.WITHER).build(); + final ChatColor[] values = ChatColor.values(); + COLOUR_CHARACTER_LIST = new TCharArrayList(values.length); + for (final ChatColor colour : values) { + BukkitUtils.COLOUR_CHARACTER_LIST.add(colour.getChar()); + } + } +} diff --git a/src/LorexMC/us/utils/Color.java b/src/LorexMC/us/utils/Color.java new file mode 100644 index 0000000..68c2861 --- /dev/null +++ b/src/LorexMC/us/utils/Color.java @@ -0,0 +1,18 @@ +package LorexMC.us.utils; + +import org.bukkit.*; +import java.util.*; + +public class Color { + public static String translate(final String input) { + return ChatColor.translateAlternateColorCodes('&', input); + } + + public static List translateFromArray(final List text) { + final List messages = new ArrayList(); + for (final String string : text) { + messages.add(translate(string)); + } + return messages; + } +} diff --git a/src/LorexMC/us/utils/ConcurrentValueOrderedMap.java b/src/LorexMC/us/utils/ConcurrentValueOrderedMap.java new file mode 100644 index 0000000..a793a7c --- /dev/null +++ b/src/LorexMC/us/utils/ConcurrentValueOrderedMap.java @@ -0,0 +1,89 @@ +package LorexMC.us.utils; + +import java.io.*; +import java.util.concurrent.*; +import java.util.*; +import javax.annotation.*; + +public class ConcurrentValueOrderedMap> extends AbstractMap + implements Map, Cloneable, Serializable { + private final Set> ordering; + private final ConcurrentMap> lookup; + + public ConcurrentValueOrderedMap() { + this.ordering = new ConcurrentSkipListSet>(); + this.lookup = new ConcurrentHashMap>(); + } + + @Override + public V get(final Object key) { + final InternalEntry old = this.lookup.get(key); + return (old != null) ? old.getValue() : null; + } + + @Override + public V put(final K key, final V val) { + final InternalEntry entry = new InternalEntry(key, val); + final InternalEntry old = this.lookup.put(key, entry); + if (old == null) { + this.ordering.add(entry); + return null; + } + this.ordering.remove(old); + this.ordering.add(entry); + return old.getValue(); + } + + @Override + public V remove(final Object key) { + final InternalEntry old = this.lookup.remove(key); + if (old != null) { + this.ordering.remove(old); + return old.getValue(); + } + return null; + } + + @Override + public void clear() { + this.ordering.clear(); + this.lookup.clear(); + } + + @Nonnull + @Override + public Set> entrySet() { + return Collections.unmodifiableSet((Set>) this.ordering); + } + + private static class InternalEntry> + implements Comparable>, Entry { + private final K key; + private final V value; + + InternalEntry(final K key, final V value) { + this.key = key; + this.value = value; + } + + @Override + public K getKey() { + return this.key; + } + + @Override + public V getValue() { + return this.value; + } + + @Override + public V setValue(final V value) throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + @Override + public int compareTo(@Nonnull final InternalEntry o) { + return o.value.compareTo(this.value); + } + } +} diff --git a/src/LorexMC/us/utils/Config.java b/src/LorexMC/us/utils/Config.java new file mode 100644 index 0000000..692b447 --- /dev/null +++ b/src/LorexMC/us/utils/Config.java @@ -0,0 +1,93 @@ +package LorexMC.us.utils; + +import org.bukkit.configuration.file.*; +import org.bukkit.plugin.java.*; +import java.io.*; + +public class Config extends YamlConfiguration { + private final String fileName; + private final JavaPlugin plugin; + + public Config(final JavaPlugin plugin, final String fileName) { + this(plugin, fileName, ".yml"); + } + + public Config(final JavaPlugin plugin, final String fileName, final String fileExtension) { + this.plugin = plugin; + this.fileName = fileName + (fileName.endsWith(fileExtension) ? "" : fileExtension); + this.createFile(); + } + + public String getFileName() { + return this.fileName; + } + + public JavaPlugin getPlugin() { + return this.plugin; + } + + private void createFile() { + final File folder = this.plugin.getDataFolder(); + try { + final File file = new File(folder, this.fileName); + if (!file.exists()) { + if (this.plugin.getResource(this.fileName) != null) { + this.plugin.saveResource(this.fileName, false); + } else { + this.save(file); + } + this.load(file); + } else { + this.load(file); + this.save(file); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void save() { + final File folder = this.plugin.getDataFolder(); + try { + this.save(new File(folder, this.fileName)); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Config)) { + return false; + } + final Config config = (Config) o; + Label_0054: { + if (this.fileName != null) { + if (this.fileName.equals(config.fileName)) { + break Label_0054; + } + } else if (config.fileName == null) { + break Label_0054; + } + return false; + } + if (this.plugin != null) { + if (!this.plugin.equals(config.plugin)) { + return false; + } + } else if (config.plugin != null) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = (this.fileName != null) ? this.fileName.hashCode() : 0; + result = 31 * result + ((this.plugin != null) ? this.plugin.hashCode() : 0); + return result; + } +} diff --git a/src/LorexMC/us/utils/DelayedMessageRunnable.java b/src/LorexMC/us/utils/DelayedMessageRunnable.java new file mode 100644 index 0000000..8afd21c --- /dev/null +++ b/src/LorexMC/us/utils/DelayedMessageRunnable.java @@ -0,0 +1,22 @@ +package LorexMC.us.utils; + +import org.bukkit.scheduler.*; +import org.bukkit.entity.*; +import org.bukkit.plugin.java.*; +import org.bukkit.plugin.*; + +public class DelayedMessageRunnable extends BukkitRunnable { + private final Player player; + private final String message; + + public DelayedMessageRunnable(final JavaPlugin plugin, final Player player, final String message) { + this.player = player; + this.message = message; + this.runTask(plugin); + } + + @Override + public void run() { + this.player.sendMessage(this.message); + } +} diff --git a/src/LorexMC/us/utils/DurationFormatter.java b/src/LorexMC/us/utils/DurationFormatter.java new file mode 100644 index 0000000..5c0b1a7 --- /dev/null +++ b/src/LorexMC/us/utils/DurationFormatter.java @@ -0,0 +1,30 @@ +package LorexMC.us.utils; + +import org.apache.commons.lang3.time.*; + +import me.bruce.factions.listener.DateTimeFormats; + +import java.util.concurrent.*; + +public class DurationFormatter { + private static final long MINUTE; + private static final long HOUR; + + public static String getRemaining(final long millis, final boolean milliseconds) { + return getRemaining(millis, milliseconds, true); + } + + public static String getRemaining(final long duration, final boolean milliseconds, final boolean trail) { + if (milliseconds && duration < DurationFormatter.MINUTE) { + return (trail ? DateTimeFormats.REMAINING_SECONDS_TRAILING : DateTimeFormats.REMAINING_SECONDS).get() + .format(duration * 0.001); + } + return DurationFormatUtils.formatDuration(duration, + ((duration >= DurationFormatter.HOUR) ? "HH:" : "") + "mm:ss"); + } + + static { + MINUTE = TimeUnit.MINUTES.toMillis(1L); + HOUR = TimeUnit.HOURS.toMillis(1L); + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/ExperienceManager.java b/src/LorexMC/us/utils/ExperienceManager.java new file mode 100644 index 0000000..402a638 --- /dev/null +++ b/src/LorexMC/us/utils/ExperienceManager.java @@ -0,0 +1,134 @@ +package LorexMC.us.utils; + +import java.lang.ref.*; +import org.bukkit.entity.*; +import com.google.common.base.*; +import java.util.*; + +public class ExperienceManager { + private static int hardMaxLevel; + private static int[] xpTotalToReachLevel; + private final WeakReference player; + private final String playerName; + + public ExperienceManager(final Player player) { + Preconditions.checkNotNull((Object) player, (Object) "Player cannot be null"); + this.player = new WeakReference(player); + this.playerName = player.getName(); + } + + public static int getHardMaxLevel() { + return ExperienceManager.hardMaxLevel; + } + + public static void setHardMaxLevel(final int hardMaxLevel) { + ExperienceManager.hardMaxLevel = hardMaxLevel; + } + + private static void initLookupTables(final int maxLevel) { + ExperienceManager.xpTotalToReachLevel = new int[maxLevel]; + for (int i = 0; i < ExperienceManager.xpTotalToReachLevel.length; ++i) { + ExperienceManager.xpTotalToReachLevel[i] = ((i >= 30) ? ((int) (3.5 * i * i - 151.5 * i + 2220.0)) + : ((i >= 16) ? ((int) (1.5 * i * i - 29.5 * i + 360.0)) : (17 * i))); + } + } + + private static int calculateLevelForExp(final int exp) { + int level = 0; + for (int curExp = 7, incr = 10; curExp <= exp; curExp += incr, ++level, incr += ((level % 2 == 0) ? 3 : 4)) { + } + return level; + } + + public Player getPlayer() { + final Player p = this.player.get(); + if (p == null) { + throw new IllegalStateException("Player " + this.playerName + " is not online"); + } + return p; + } + + public void changeExp(final int amt) { + this.changeExp((double) amt); + } + + public void changeExp(final double amt) { + this.setExp(this.getCurrentFractionalXP(), amt); + } + + public void setExp(final int amt) { + this.setExp(0.0, amt); + } + + public void setExp(final double amt) { + this.setExp(0.0, amt); + } + + private void setExp(final double base, final double amt) { + final int xp = (int) Math.max(base + amt, 0.0); + final Player player = this.getPlayer(); + final int curLvl = player.getLevel(); + final int newLvl = this.getLevelForExp(xp); + if (curLvl != newLvl) { + player.setLevel(newLvl); + } + if (xp > base) { + player.setTotalExperience(player.getTotalExperience() + xp - (int) base); + } + final double pct = (base - this.getXpForLevel(newLvl) + amt) / this.getXpNeededToLevelUp(newLvl); + player.setExp((float) pct); + } + + public int getCurrentExp() { + final Player player = this.getPlayer(); + final int lvl = player.getLevel(); + return this.getXpForLevel(lvl) + Math.round(this.getXpNeededToLevelUp(lvl) * player.getExp()); + } + + private double getCurrentFractionalXP() { + final Player player = this.getPlayer(); + final int lvl = player.getLevel(); + return this.getXpForLevel(lvl) + this.getXpNeededToLevelUp(lvl) * player.getExp(); + } + + public boolean hasExp(final int amt) { + return this.getCurrentExp() >= amt; + } + + public boolean hasExp(final double amt) { + return this.getCurrentFractionalXP() >= amt; + } + + public int getLevelForExp(final int exp) { + if (exp <= 0) { + return 0; + } + if (exp > ExperienceManager.xpTotalToReachLevel[ExperienceManager.xpTotalToReachLevel.length - 1]) { + final int newMax = calculateLevelForExp(exp) * 2; + Preconditions.checkArgument(newMax <= ExperienceManager.hardMaxLevel, + "Level for exp " + exp + " > hard max level " + ExperienceManager.hardMaxLevel); + initLookupTables(newMax); + } + final int pos = Arrays.binarySearch(ExperienceManager.xpTotalToReachLevel, exp); + return (pos < 0) ? (-pos - 2) : pos; + } + + public int getXpNeededToLevelUp(final int level) { + Preconditions.checkArgument(level >= 0, "Level may not be negative."); + return (level > 30) ? (62 + (level - 30) * 7) : ((level >= 16) ? (17 + (level - 15) * 3) : 17); + } + + public int getXpForLevel(final int level) { + Preconditions.checkArgument(level >= 0 && level <= ExperienceManager.hardMaxLevel, + "Invalid level " + level + "(must be in range 0.." + ExperienceManager.hardMaxLevel + ')'); + if (level >= ExperienceManager.xpTotalToReachLevel.length) { + initLookupTables(level * 2); + } + return ExperienceManager.xpTotalToReachLevel[level]; + } + + static { + ExperienceManager.hardMaxLevel = 100000; + initLookupTables(25); + } +} diff --git a/src/LorexMC/us/utils/GenericUtils.java b/src/LorexMC/us/utils/GenericUtils.java new file mode 100644 index 0000000..08b18b4 --- /dev/null +++ b/src/LorexMC/us/utils/GenericUtils.java @@ -0,0 +1,69 @@ +package LorexMC.us.utils; + +import java.util.*; + +public final class GenericUtils { + public static List createList(final Object object, final Class type) { + final List output = new ArrayList(); + if (object != null && object instanceof List) { + final List input = (List) object; + for (final Object value : input) { + if (value != null) { + if (value.getClass() == null) { + continue; + } + if (!type.isAssignableFrom(value.getClass())) { + final String simpleName = type.getSimpleName(); + throw new AssertionError("Cannot cast to list! Key " + value + " is not a " + simpleName); + } + final E e = type.cast(value); + output.add(e); + } + } + } + return output; + } + + public static Set castSet(final Object object, final Class type) { + final Set output = new HashSet(); + if (object != null && object instanceof List) { + final List input = (List) object; + for (final Object value : input) { + if (value != null) { + if (value.getClass() == null) { + continue; + } + if (!type.isAssignableFrom(value.getClass())) { + final String simpleName = type.getSimpleName(); + throw new AssertionError("Cannot cast to list! Key " + value + " is not a " + simpleName); + } + final E e = type.cast(value); + output.add(e); + } + } + } + return output; + } + + public static Map castMap(final Object object, final Class keyClass, final Class valueClass) { + final Map output = new HashMap(); + if (object != null && object instanceof Map) { + final Map input = (Map) object; + final String keyClassName = keyClass.getSimpleName(); + final String valueClassName = valueClass.getSimpleName(); + for (final Object key : input.keySet().toArray()) { + if (key != null && !keyClass.isAssignableFrom(key.getClass())) { + throw new AssertionError("Cannot cast to HashMap: " + keyClassName + ", " + keyClassName + + ". Value " + valueClassName + " is not a " + keyClassName); + } + final Object value = input.get(key); + if (value != null && !valueClass.isAssignableFrom(value.getClass())) { + throw new AssertionError("Cannot cast to HashMap: " + valueClassName + ", " + valueClassName + + ". Key " + key + " is not a " + valueClassName); + } + output.put(keyClass.cast(key), valueClass.cast(value)); + } + } + return output; + } +} diff --git a/src/LorexMC/us/utils/InventorySerialisation.java b/src/LorexMC/us/utils/InventorySerialisation.java new file mode 100644 index 0000000..9eb4455 --- /dev/null +++ b/src/LorexMC/us/utils/InventorySerialisation.java @@ -0,0 +1,75 @@ +package LorexMC.us.utils; + +import org.yaml.snakeyaml.external.biz.base64Coder.*; +import org.bukkit.util.io.*; +import org.bukkit.*; +import org.bukkit.inventory.*; +import java.io.*; + +public class InventorySerialisation { + public static String[] playerInventoryToBase64(final PlayerInventory playerInventory) throws IllegalStateException { + final String content = toBase64(playerInventory); + final String armor = itemStackArrayToBase64(playerInventory.getArmorContents()); + return new String[] { content, armor }; + } + + public static String itemStackArrayToBase64(final ItemStack[] items) throws IllegalStateException { + try { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + final BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); + dataOutput.writeInt(items.length); + for (final ItemStack item : items) { + dataOutput.writeObject(item); + } + dataOutput.close(); + return Base64Coder.encodeLines(outputStream.toByteArray()); + } catch (Exception e) { + throw new IllegalStateException("Unable to save item stacks.", e); + } + } + + public static String toBase64(final Inventory inventory) throws IllegalStateException { + try { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + final BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); + dataOutput.writeInt(inventory.getSize()); + for (int i = 0; i < inventory.getSize(); ++i) { + dataOutput.writeObject(inventory.getItem(i)); + } + dataOutput.close(); + return Base64Coder.encodeLines(outputStream.toByteArray()); + } catch (Exception e) { + throw new IllegalStateException("Unable to save item stacks.", e); + } + } + + public static Inventory fromBase64(final String data) throws IOException { + try { + final ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); + final BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); + final Inventory inventory = Bukkit.createInventory((InventoryHolder) null, dataInput.readInt()); + for (int i = 0; i < inventory.getSize(); ++i) { + inventory.setItem(i, (ItemStack) dataInput.readObject()); + } + dataInput.close(); + return inventory; + } catch (ClassNotFoundException e) { + throw new IOException("Unable to decode class type.", e); + } + } + + public static ItemStack[] itemStackArrayFromBase64(final String data) throws IOException { + try { + final ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); + final BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); + final ItemStack[] items = new ItemStack[dataInput.readInt()]; + for (int i = 0; i < items.length; ++i) { + items[i] = (ItemStack) dataInput.readObject(); + } + dataInput.close(); + return items; + } catch (ClassNotFoundException ex) { + throw new IOException("Unable to decode class type.", ex); + } + } +} diff --git a/src/LorexMC/us/utils/InventoryUtils.java b/src/LorexMC/us/utils/InventoryUtils.java new file mode 100644 index 0000000..c8209ac --- /dev/null +++ b/src/LorexMC/us/utils/InventoryUtils.java @@ -0,0 +1,117 @@ +package LorexMC.us.utils; + +import com.google.common.base.*; +import org.bukkit.*; +import org.bukkit.event.inventory.*; +import org.bukkit.inventory.*; +import java.util.*; + +public final class InventoryUtils { + public static final int DEFAULT_INVENTORY_WIDTH = 9; + public static final int MINIMUM_INVENTORY_HEIGHT = 1; + public static final int MINIMUM_INVENTORY_SIZE = 9; + public static final int MAXIMUM_INVENTORY_HEIGHT = 6; + public static final int MAXIMUM_INVENTORY_SIZE = 54; + public static final int MAXIMUM_SINGLE_CHEST_SIZE = 27; + public static final int MAXIMUM_DOUBLE_CHEST_SIZE = 54; + + public static ItemStack[] deepClone(final ItemStack[] origin) { + Preconditions.checkNotNull((Object) origin, (Object) "Origin cannot be null"); + final ItemStack[] cloned = new ItemStack[origin.length]; + for (int i = 0; i < origin.length; ++i) { + final ItemStack next = origin[i]; + cloned[i] = ((next == null) ? null : next.clone()); + } + return cloned; + } + + public static int getSafestInventorySize(final int initialSize) { + return (initialSize + 8) / 9 * 9; + } + + public static void removeItem(final Inventory inventory, final Material type, final short data, + final int quantity) { + final ItemStack[] contents = inventory.getContents(); + final boolean compareDamage = type.getMaxDurability() == 0; + for (int i = quantity; i > 0; --i) { + for (final ItemStack content : contents) { + if (content != null) { + if (content.getType() == type) { + if (!compareDamage || content.getData().getData() == data) { + if (content.getAmount() <= 1) { + inventory.removeItem(new ItemStack[] { content }); + break; + } + content.setAmount(content.getAmount() - 1); + break; + } + } + } + } + } + } + + public static int countAmount(final Inventory inventory, final Material type, final short data) { + final ItemStack[] contents = inventory.getContents(); + final boolean compareDamage = type.getMaxDurability() == 0; + int counter = 0; + for (final ItemStack item : contents) { + if (item != null) { + if (item.getType() == type) { + if (!compareDamage || item.getData().getData() == data) { + counter += item.getAmount(); + } + } + } + } + return counter; + } + + public static boolean isEmpty(final Inventory inventory) { + return isEmpty(inventory, true); + } + + public static boolean isEmpty(final Inventory inventory, final boolean checkArmour) { + boolean result = true; + final ItemStack[] contents2; + ItemStack[] contents = contents2 = inventory.getContents(); + for (final ItemStack content : contents2) { + if (content != null && content.getType() != Material.AIR) { + result = false; + break; + } + } + if (!result) { + return false; + } + if (checkArmour && inventory instanceof PlayerInventory) { + final ItemStack[] armorContents; + contents = (armorContents = ((PlayerInventory) inventory).getArmorContents()); + for (final ItemStack content : armorContents) { + if (content != null && content.getType() != Material.AIR) { + result = false; + break; + } + } + } + return result; + } + + public static boolean clickedTopInventory(final InventoryDragEvent event) { + final InventoryView view = event.getView(); + final Inventory topInventory = view.getTopInventory(); + if (topInventory == null) { + return false; + } + boolean result = false; + final Set> entrySet = event.getNewItems().entrySet(); + final int size = topInventory.getSize(); + for (final Map.Entry entry : entrySet) { + if (entry.getKey() < size) { + result = true; + break; + } + } + return result; + } +} diff --git a/src/LorexMC/us/utils/ItemBuilder.java b/src/LorexMC/us/utils/ItemBuilder.java new file mode 100644 index 0000000..8badde0 --- /dev/null +++ b/src/LorexMC/us/utils/ItemBuilder.java @@ -0,0 +1,84 @@ +package LorexMC.us.utils; + +import org.bukkit.inventory.*; +import org.bukkit.inventory.meta.*; +import org.bukkit.*; +import com.google.common.base.*; +import java.util.*; +import org.bukkit.enchantments.*; + +public class ItemBuilder { + private ItemStack stack; + private ItemMeta meta; + + public ItemBuilder(final Material material) { + this(material, 1); + } + + public ItemBuilder(final Material material, final int amount) { + this(material, amount, (byte) 0); + } + + public ItemBuilder(final ItemStack stack) { + Preconditions.checkNotNull((Object) stack, (Object) "ItemStack cannot be null"); + this.stack = stack; + } + + public ItemBuilder(final Material material, final int amount, final byte data) { + Preconditions.checkNotNull((Object) material, (Object) "Material cannot be null"); + Preconditions.checkArgument(amount > 0, "Amount must be positive"); + this.stack = new ItemStack(material, amount, data); + } + + public ItemBuilder displayName(final String name) { + if (this.meta == null) { + this.meta = this.stack.getItemMeta(); + } + this.meta.setDisplayName(name); + return this; + } + + public ItemBuilder loreLine(final String line) { + if (this.meta == null) { + this.meta = this.stack.getItemMeta(); + } + final boolean hasLore = this.meta.hasLore(); + final List lore = hasLore ? this.meta.getLore() : new ArrayList(); + lore.add(hasLore ? lore.size() : 0, line); + this.lore(line); + return this; + } + + public ItemBuilder lore(final String... lore) { + if (this.meta == null) { + this.meta = this.stack.getItemMeta(); + } + this.meta.setLore(Arrays.asList(lore)); + return this; + } + + public ItemBuilder enchant(final Enchantment enchantment, final int level) { + return this.enchant(enchantment, level, true); + } + + public ItemBuilder enchant(final Enchantment enchantment, final int level, final boolean unsafe) { + if (unsafe && level >= enchantment.getMaxLevel()) { + this.stack.addUnsafeEnchantment(enchantment, level); + } else { + this.stack.addEnchantment(enchantment, level); + } + return this; + } + + public ItemBuilder data(final short data) { + this.stack.setDurability(data); + return this; + } + + public ItemStack build() { + if (this.meta != null) { + this.stack.setItemMeta(this.meta); + } + return this.stack; + } +} diff --git a/src/LorexMC/us/utils/JavaUtils.java b/src/LorexMC/us/utils/JavaUtils.java new file mode 100644 index 0000000..849f236 --- /dev/null +++ b/src/LorexMC/us/utils/JavaUtils.java @@ -0,0 +1,133 @@ +package LorexMC.us.utils; + +import java.util.regex.*; +import org.apache.commons.lang3.*; +import java.math.*; +import com.google.common.base.*; +import java.util.*; +import java.util.concurrent.*; + +public final class JavaUtils { + private static final CharMatcher CHAR_MATCHER_ASCII; + private static final Pattern UUID_PATTERN; + private static final int DEFAULT_NUMBER_FORMAT_DECIMAL_PLACES = 5; + + public static Integer tryParseInt(final String string) { + try { + return Integer.parseInt(string); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public static Double tryParseDouble(final String string) { + try { + return Double.parseDouble(string); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public static boolean isUUID(final String string) { + return JavaUtils.UUID_PATTERN.matcher(string).find(); + } + + public static boolean isAlphanumeric(final String string) { + return JavaUtils.CHAR_MATCHER_ASCII.matchesAllOf(string); + } + + public static boolean containsIgnoreCase(final Iterable elements, final String string) { + for (final String element : elements) { + if (StringUtils.containsIgnoreCase(element, string)) { + return true; + } + } + return false; + } + + public static String format(final Number number) { + return format(number, 5); + } + + public static String format(final Number number, final int decimalPlaces) { + return format(number, decimalPlaces, RoundingMode.HALF_DOWN); + } + + public static String format(final Number number, final int decimalPlaces, final RoundingMode roundingMode) { + Preconditions.checkNotNull((Object) number, (Object) "The number cannot be null"); + return new BigDecimal(number.toString()).setScale(decimalPlaces, roundingMode).stripTrailingZeros() + .toPlainString(); + } + + public static String andJoin(final Collection collection, final boolean delimiterBeforeAnd) { + return andJoin(collection, delimiterBeforeAnd, ", "); + } + + public static String andJoin(final Collection collection, final boolean delimiterBeforeAnd, + final String delimiter) { + if (collection == null || collection.isEmpty()) { + return ""; + } + final List contents = new ArrayList(collection); + final String last = contents.remove(contents.size() - 1); + final StringBuilder builder = new StringBuilder(Joiner.on(delimiter).join(contents)); + if (delimiterBeforeAnd) { + builder.append(delimiter); + } + return builder.append(" and ").append(last).toString(); + } + + public static long parse(final String input) { + if (input == null || input.isEmpty()) { + return -1L; + } + long result = 0L; + StringBuilder number = new StringBuilder(); + for (int i = 0; i < input.length(); ++i) { + final char c = input.charAt(i); + if (Character.isDigit(c)) { + number.append(c); + } else { + final String str; + if (Character.isLetter(c) && !(str = number.toString()).isEmpty()) { + result += convert(Integer.parseInt(str), c); + number = new StringBuilder(); + } + } + } + return result; + } + + private static long convert(final int value, final char unit) { + switch (unit) { + case 'y': { + return value * TimeUnit.DAYS.toMillis(365L); + } + case 'M': { + return value * TimeUnit.DAYS.toMillis(30L); + } + case 'd': { + return value * TimeUnit.DAYS.toMillis(1L); + } + case 'h': { + return value * TimeUnit.HOURS.toMillis(1L); + } + case 'm': { + return value * TimeUnit.MINUTES.toMillis(1L); + } + case 's': { + return value * TimeUnit.SECONDS.toMillis(1L); + } + default: { + return -1L; + } + } + } + + static { + CHAR_MATCHER_ASCII = CharMatcher.inRange('0', '9').or(CharMatcher.inRange('a', 'z')) + .or(CharMatcher.inRange('A', 'Z')).or(CharMatcher.WHITESPACE).precomputed(); + UUID_PATTERN = Pattern + .compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}"); + } +} diff --git a/src/LorexMC/us/utils/MapSorting.java b/src/LorexMC/us/utils/MapSorting.java new file mode 100644 index 0000000..95d6e1c --- /dev/null +++ b/src/LorexMC/us/utils/MapSorting.java @@ -0,0 +1,84 @@ +package LorexMC.us.utils; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; +import com.google.common.collect.Ordering; + +@SuppressWarnings("rawtypes") +public class MapSorting { + // Building block - extract key from entry + private static final Function EXTRACT_KEY = new Function, Object>() { + @Override + public Object apply(Entry input) { + return input.getKey(); + } + }; + // Same as above, only we extract the value + private static final Function EXTRACT_VALUE = new Function, Object>() { + @Override + public Object apply(Entry input) { + return input.getValue(); + } + }; + + /** + * Sort the given map by the value in each entry. + * + * @param map + * - map of comparable values. + * @return A new list with the sort result. + */ + public static > List> sortedValues(Map map) { + return sortedValues(map, Ordering.natural()); + } + + /** + * Sort the given map by the value in each entry. + * + * @param map + * - map of comparable values. + * @param valueComparator + * - object for comparing each values. + * @return A new list with the sort result. + */ + public static List> sortedValues(Map map, Comparator valueComparator) { + return Ordering.from(valueComparator).onResultOf(MapSorting.extractValue()).sortedCopy(map.entrySet()); + } + + /** + * Retrieve every key in the entry list in order. + * + * @param entryList + * - the entry list. + * @return Every key in order. + */ + public static Iterable keys(List> entryList) { + return Iterables.transform(entryList, MapSorting.extractKey()); + } + + /** + * Retrieve every value in the entry list in order. + * + * @param entryList + * - the entry list. + * @return Every value in order. + */ + public static Iterable values(List> entryList) { + return Iterables.transform(entryList, MapSorting.extractValue()); + } + + @SuppressWarnings("unchecked") + private static Function, T> extractKey() { + return EXTRACT_KEY; + } + + @SuppressWarnings("unchecked") + private static Function, V> extractValue() { + return EXTRACT_VALUE; + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/NmsUtils.java b/src/LorexMC/us/utils/NmsUtils.java new file mode 100644 index 0000000..0c85575 --- /dev/null +++ b/src/LorexMC/us/utils/NmsUtils.java @@ -0,0 +1,53 @@ +package LorexMC.us.utils; + +import org.bukkit.entity.*; +import org.bukkit.craftbukkit.v1_7_R4.entity.*; + +import net.minecraft.server.v1_7_R4.*; +import net.minecraft.server.v1_7_R4.ItemStack; +import net.minecraft.server.v1_7_R4.PlayerInventory; + +import org.bukkit.inventory.*; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; + +public class NmsUtils { + public static int getProtocolVersion(final Player player) { + return ((CraftPlayer) player).getHandle().playerConnection.networkManager.getVersion(); + } + + public static void resendHeldItemPacket(final Player player) { + sendItemPacketAtHeldSlot(player, getCleanHeldItem(player)); + } + + public static void sendItemPacketAtHeldSlot(final Player player, final ItemStack stack) { + sendItemPacketAtSlot(player, stack, player.getInventory().getHeldItemSlot()); + } + + public static void sendItemPacketAtSlot(final Player player, final ItemStack stack, final int index) { + sendItemPacketAtSlot(player, stack, index, ((CraftPlayer) player).getHandle().defaultContainer.windowId); + } + + public static void sendItemPacketAtSlot(final Player player, final ItemStack stack, int index, final int windowID) { + final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + if (entityPlayer.playerConnection != null) { + if (index < PlayerInventory.getHotbarSize()) { + index += 36; + } else if (index > 35) { + index = 8 - (index - 36); + } + entityPlayer.playerConnection.sendPacket(new PacketPlayOutSetSlot(windowID, index, stack)); + } + } + + public static ItemStack getCleanItem(final Inventory inventory, final int slot) { + return ((CraftInventory) inventory).getInventory().getItem(slot); + } + + public static ItemStack getCleanItem(final Player player, final int slot) { + return getCleanItem(player.getInventory(), slot); + } + + public static ItemStack getCleanHeldItem(final Player player) { + return getCleanItem(player, player.getInventory().getHeldItemSlot()); + } +} diff --git a/src/LorexMC/us/utils/ParticleEffect.java b/src/LorexMC/us/utils/ParticleEffect.java new file mode 100644 index 0000000..1bb0dd7 --- /dev/null +++ b/src/LorexMC/us/utils/ParticleEffect.java @@ -0,0 +1,156 @@ +package LorexMC.us.utils; + +import org.bukkit.craftbukkit.v1_7_R4.entity.*; + +import org.bukkit.entity.*; +import javax.annotation.*; + +import com.google.common.base.*; + +import org.bukkit.*; +import org.bukkit.World; + +import net.minecraft.server.v1_7_R4.*; + +public enum ParticleEffect { + HUGE_EXPLODE("hugeexplosion", 0), LARGE_EXPLODE("largeexplode", 1), FIREWORK_SPARK("fireworksSpark", 2), AIR_BUBBLE( + "bubble", + 3), SUSPEND("suspend", 4), DEPTH_SUSPEND("depthSuspend", 5), TOWN_AURA("townaura", 6), CRITICAL_HIT("crit", + 7), MAGIC_CRITICAL_HIT("magicCrit", 8), MOB_SPELL("mobSpell", 9), MOB_SPELL_AMBIENT( + "mobSpellAmbient", 10), SPELL("spell", 11), INSTANT_SPELL("instantSpell", 12), BLUE_SPARKLE( + "witchMagic", 13), NOTE_BLOCK("note", 14), ENDER("portal", 15), ENCHANTMENT_TABLE( + "enchantmenttable", + 16), EXPLODE("explode", 17), FIRE("flame", 18), LAVA_SPARK("lava", + 19), FOOTSTEP("footstep", 20), SPLASH("splash", 21), LARGE_SMOKE( + "largesmoke", + 22), CLOUD("cloud", 23), REDSTONE_DUST("reddust", + 24), SNOWBALL_HIT("snowballpoof", 25), DRIP_WATER( + "dripWater", + 26), DRIP_LAVA("dripLava", 27), SNOW_DIG( + "snowshovel", + 28), SLIME("slime", 29), HEART( + "heart", + 30), ANGRY_VILLAGER( + "angryVillager", + 31), GREEN_SPARKLE( + "happyVillager", + 32), ICONCRACK( + "iconcrack", + 33), TILECRACK( + "tilecrack", + 34); + + private final String name; + @Deprecated + private final int id; + + private ParticleEffect(final String name, final int id) { + this.name = name; + this.id = id; + } + + @Deprecated + String getName() { + return this.name; + } + + @Deprecated + public int getId() { + return this.id; + } + + public void display(final Player player, final float x, final float y, final float z, final float speed, + final int amount) { + this.display(player, x, y, z, 0.0f, 0.0f, 0.0f, speed, amount); + } + + public void display(final Player player, final float x, final float y, final float z, final float offsetX, + final float offsetY, final float offsetZ, final float speed, final int amount) { + final Packet packet = this.createPacket(x, y, z, offsetX, offsetY, offsetZ, speed, amount); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + public void display(final Player player, final Location location, final float speed, final int amount) { + this.display(player, location, 0.0f, 0.0f, 0.0f, speed, amount); + } + + public void display(final Player player, final Location location, final float offsetX, final float offsetY, + final float offsetZ, final float speed, final int amount) { + final Packet packet = this.createPacket(location, offsetX, offsetY, offsetZ, speed, amount); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + public void broadcast(final float x, final float y, final float z, final float offsetX, final float offsetY, + final float offsetZ, final float speed, final int amount) { + final Packet packet = this.createPacket(x, y, z, offsetX, offsetY, offsetZ, speed, amount); + for (final Player player : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + + public void broadcast(final Location location, final float offsetX, final float offsetY, final float offsetZ, + final float speed, final int amount) { + this.broadcast(location, offsetX, offsetY, offsetZ, speed, amount, null, null); + } + + public void broadcast(final Location location, final float offsetX, final float offsetY, final float offsetZ, + final float speed, final int amount, @Nullable final Player source) { + this.broadcast(location, offsetX, offsetY, offsetZ, speed, amount, source, null); + } + + public void broadcast(final Location location, final float offsetX, final float offsetY, final float offsetZ, + final float speed, final int amount, @Nullable final Player source, + @Nullable final Predicate predicate) { + final Packet packet = this.createPacket(location, offsetX, offsetY, offsetZ, speed, amount); + for (final Player player : Bukkit.getOnlinePlayers()) { + if ((source == null || player.canSee(source)) && (predicate == null || predicate.apply(player))) { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + + public void sphere(@Nullable final Player player, final Location location, final float radius) { + this.sphere(player, location, radius, 20.0f, 2); + } + + public void sphere(@Nullable final Player player, final Location location, final float radius, final float density, + final int intensity) { + Preconditions.checkNotNull((Object) location, (Object) "Location cannot be null"); + Preconditions.checkArgument(radius >= 0.0f, "Radius must be positive"); + Preconditions.checkArgument(density >= 0.0f, "Density must be positive"); + Preconditions.checkArgument(intensity >= 0, "Intensity must be positive"); + final float deltaPitch = 180.0f / density; + final float deltaYaw = 360.0f / density; + final World world = location.getWorld(); + for (int i = 0; i < density; ++i) { + for (int j = 0; j < density; ++j) { + final float pitch = -90.0f + j * deltaPitch; + final float yaw = -180.0f + i * deltaYaw; + final float x = radius * MathHelper.sin(-yaw * 0.017453292f - 3.1415927f) + * -MathHelper.cos(-pitch * 0.017453292f) + (float) location.getX(); + final float y = radius * MathHelper.sin(-pitch * 0.017453292f) + (float) location.getY(); + final float z = radius * MathHelper.cos(-yaw * 0.017453292f - 3.1415927f) + * -MathHelper.cos(-pitch * 0.017453292f) + (float) location.getZ(); + final Location target = new Location(world, x, y, z); + if (player == null) { + this.broadcast(target, 0.0f, 0.0f, 0.0f, 0.0f, intensity); + } else { + this.display(player, target, 0.0f, 0.0f, 0.0f, 0.0f, intensity); + } + } + } + } + + private PacketPlayOutWorldParticles createPacket(final Location location, final float offsetX, final float offsetY, + final float offsetZ, final float speed, final int amount) { + return this.createPacket((float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, + offsetY, offsetZ, speed, amount); + } + + private PacketPlayOutWorldParticles createPacket(final float x, final float y, final float z, final float offsetX, + final float offsetY, final float offsetZ, final float speed, final int amount) { + Preconditions.checkArgument(speed >= 0.0f, "Speed must be positive"); + Preconditions.checkArgument(amount > 0, "Cannot use less than one particle."); + return new PacketPlayOutWorldParticles(this.name, x, y, z, offsetX, offsetY, offsetZ, speed, amount); + } +} diff --git a/src/LorexMC/us/utils/PersistableLocation.java b/src/LorexMC/us/utils/PersistableLocation.java new file mode 100644 index 0000000..4c88c6c --- /dev/null +++ b/src/LorexMC/us/utils/PersistableLocation.java @@ -0,0 +1,249 @@ +package LorexMC.us.utils; + +import org.bukkit.configuration.serialization.*; +import com.google.common.base.*; +import java.util.*; +import org.bukkit.*; + +public class PersistableLocation implements ConfigurationSerializable, Cloneable { + private Location location; + private World world; + private String worldName; + private UUID worldUID; + private double x; + private double y; + private double z; + private float yaw; + private float pitch; + + public PersistableLocation(final Location location) { + Preconditions.checkNotNull((Object) location, (Object) "Location cannot be null"); + Preconditions.checkNotNull((Object) location.getWorld(), (Object) "Locations' world cannot be null"); + this.world = location.getWorld(); + this.worldName = this.world.getName(); + this.worldUID = this.world.getUID(); + this.x = location.getX(); + this.y = location.getY(); + this.z = location.getZ(); + this.yaw = location.getYaw(); + this.pitch = location.getPitch(); + } + + public PersistableLocation(final World world, final double x, final double y, final double z) { + this.worldName = world.getName(); + this.x = x; + this.y = y; + this.z = z; + final float n = 0.0f; + this.yaw = n; + this.pitch = n; + } + + public PersistableLocation(final String worldName, final double x, final double y, final double z) { + this.worldName = worldName; + this.x = x; + this.y = y; + this.z = z; + final float n = 0.0f; + this.yaw = n; + this.pitch = n; + } + + public PersistableLocation(final Map map) { + this.worldName = map.get("worldName"); + this.worldUID = UUID.fromString(map.get("worldUID")); + Object o = map.get("x"); + if (o instanceof String) { + this.x = Double.parseDouble((String) o); + } else { + this.x = (double) o; + } + o = map.get("y"); + if (o instanceof String) { + this.y = Double.parseDouble((String) o); + } else { + this.y = (double) o; + } + o = map.get("z"); + if (o instanceof String) { + this.z = Double.parseDouble((String) o); + } else { + this.z = (double) o; + } + this.yaw = Float.parseFloat(map.get("yaw")); + this.pitch = Float.parseFloat(map.get("pitch")); + } + + @Override + public Map serialize() { + final Map map = new LinkedHashMap(); + map.put("worldName", this.worldName); + map.put("worldUID", this.worldUID.toString()); + map.put("x", this.x); + map.put("y", this.y); + map.put("z", this.z); + map.put("yaw", Float.toString(this.yaw)); + map.put("pitch", Float.toString(this.pitch)); + return map; + } + + public World getWorld() { + Preconditions.checkNotNull((Object) this.worldUID, (Object) "World UUID cannot be null"); + Preconditions.checkNotNull((Object) this.worldName, (Object) "World name cannot be null"); + if (this.world == null) { + this.world = Bukkit.getWorld(this.worldUID); + } + return this.world; + } + + public void setWorld(final World world) { + this.worldName = world.getName(); + this.worldUID = world.getUID(); + this.world = world; + } + + public Location getLocation() { + if (this.location == null) { + this.location = new Location(this.getWorld(), this.x, this.y, this.z, this.yaw, this.pitch); + } + return this.location; + } + + @Override + public PersistableLocation clone() throws CloneNotSupportedException { + try { + return (PersistableLocation) super.clone(); + } catch (CloneNotSupportedException ex) { + ex.printStackTrace(); + throw new RuntimeException(); + } + } + + @Override + public String toString() { + return "PersistableLocation [worldName=" + this.worldName + ", worldUID=" + this.worldUID + ", x=" + this.x + + ", y=" + this.y + ", z=" + this.z + ", yaw=" + this.yaw + ", pitch=" + this.pitch + ']'; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof PersistableLocation)) { + return false; + } + final PersistableLocation that = (PersistableLocation) o; + if (Double.compare(that.x, this.x) != 0) { + return false; + } + if (Double.compare(that.y, this.y) != 0) { + return false; + } + if (Double.compare(that.z, this.z) != 0) { + return false; + } + if (Float.compare(that.yaw, this.yaw) != 0) { + return false; + } + if (Float.compare(that.pitch, this.pitch) != 0) { + return false; + } + Label_0134: { + if (this.world != null) { + if (this.world.equals(that.world)) { + break Label_0134; + } + } else if (that.world == null) { + break Label_0134; + } + return false; + } + Label_0167: { + if (this.worldName != null) { + if (this.worldName.equals(that.worldName)) { + break Label_0167; + } + } else if (that.worldName == null) { + break Label_0167; + } + return false; + } + if (this.worldUID != null) { + if (!this.worldUID.equals(that.worldUID)) { + return false; + } + } else if (that.worldUID != null) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = (this.world != null) ? this.world.hashCode() : 0; + result = 31 * result + ((this.worldName != null) ? this.worldName.hashCode() : 0); + result = 31 * result + ((this.worldUID != null) ? this.worldUID.hashCode() : 0); + long temp = Double.doubleToLongBits(this.x); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(this.y); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(this.z); + result = 31 * result + (int) (temp ^ temp >>> 32); + result = 31 * result + ((this.yaw != 0.0f) ? Float.floatToIntBits(this.yaw) : 0); + result = 31 * result + ((this.pitch != 0.0f) ? Float.floatToIntBits(this.pitch) : 0); + return result; + } + + public String getWorldName() { + return this.worldName; + } + + public UUID getWorldUID() { + return this.worldUID; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + public void setWorldUID(final UUID worldUID) { + this.worldUID = worldUID; + } + + public void setX(final double x) { + this.x = x; + } + + public void setY(final double y) { + this.y = y; + } + + public void setZ(final double z) { + this.z = z; + } + + public void setYaw(final float yaw) { + this.yaw = yaw; + } + + public void setPitch(final float pitch) { + this.pitch = pitch; + } +} diff --git a/src/LorexMC/us/utils/SignHandler.java b/src/LorexMC/us/utils/SignHandler.java new file mode 100644 index 0000000..54cbba0 --- /dev/null +++ b/src/LorexMC/us/utils/SignHandler.java @@ -0,0 +1,124 @@ +package LorexMC.us.utils; + +import org.bukkit.plugin.java.*; +import com.google.common.collect.*; +import org.bukkit.event.*; +import org.bukkit.event.player.*; +import org.bukkit.entity.*; +import org.bukkit.scheduler.*; +import org.bukkit.block.*; +import org.bukkit.*; +import org.bukkit.plugin.*; +import javax.annotation.*; +import java.util.*; + +public class SignHandler implements Listener { + private final Multimap signUpdateMap; + private final JavaPlugin plugin; + + public SignHandler(final JavaPlugin plugin) { + this.signUpdateMap = HashMultimap.create(); + this.plugin = plugin; + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerKick(final PlayerQuitEvent event) { + this.cancelTasks(event.getPlayer(), null, false); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerQuit(final PlayerQuitEvent event) { + this.cancelTasks(event.getPlayer(), null, false); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onWorldChange(final PlayerChangedWorldEvent event) { + this.cancelTasks(event.getPlayer(), null, false); + } + + public boolean showLines(final Player player, final Sign sign, final String[] newLines, final long ticks, + final boolean forceChange) { + final String[] lines = sign.getLines(); + if (Arrays.equals(lines, newLines)) { + return false; + } + final Collection signChanges = this.getSignChanges(player); + final Iterator iterator = signChanges.iterator(); + while (iterator.hasNext()) { + final SignChange signChange = iterator.next(); + if (signChange.sign.equals(sign)) { + if (!forceChange && Arrays.equals(signChange.newLines, newLines)) { + return false; + } + signChange.runnable.cancel(); + iterator.remove(); + break; + } + } + final Location location = sign.getLocation(); + player.sendSignChange(location, newLines); + SignChange signChange; + if (signChanges.add(signChange = new SignChange(sign, newLines))) { + final Block block = sign.getBlock(); + final BlockState previous = block.getState(); + final BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + if (SignHandler.this.signUpdateMap.remove(player.getUniqueId(), signChange) + && previous.equals(block.getState())) { + player.sendSignChange(location, lines); + } + } + }; + runnable.runTaskLater(this.plugin, ticks); + signChange.runnable = runnable; + } + return true; + } + + public Collection getSignChanges(final Player player) { + return this.signUpdateMap.get(player.getUniqueId()); + } + + public void cancelTasks(@Nullable final Sign sign) { + final Iterator iterator = this.signUpdateMap.values().iterator(); + while (iterator.hasNext()) { + final SignChange signChange = iterator.next(); + if (sign == null || signChange.sign.equals(sign)) { + signChange.runnable.cancel(); + signChange.sign.update(); + iterator.remove(); + } + } + } + + public void cancelTasks(final Player player, @Nullable final Sign sign, final boolean revertLines) { + final UUID uuid = player.getUniqueId(); + final Iterator> iterator = this.signUpdateMap.entries().iterator(); + while (iterator.hasNext()) { + final Map.Entry entry = iterator.next(); + if (entry.getKey().equals(uuid)) { + final SignChange signChange = entry.getValue(); + if (sign != null && !signChange.sign.equals(sign)) { + continue; + } + if (revertLines) { + player.sendSignChange(signChange.sign.getLocation(), signChange.sign.getLines()); + } + signChange.runnable.cancel(); + iterator.remove(); + } + } + } + + private static final class SignChange { + public BukkitRunnable runnable; + public final Sign sign; + public final String[] newLines; + + public SignChange(final Sign sign, final String[] newLines) { + this.sign = sign; + this.newLines = newLines; + } + } +} diff --git a/src/LorexMC/us/utils/SpigotUtils.java b/src/LorexMC/us/utils/SpigotUtils.java new file mode 100644 index 0000000..c666cc2 --- /dev/null +++ b/src/LorexMC/us/utils/SpigotUtils.java @@ -0,0 +1,79 @@ +package LorexMC.us.utils; + +import org.bukkit.*; + +public class SpigotUtils { + public static net.md_5.bungee.api.ChatColor toBungee(final ChatColor color) { + switch (color) { + case BLACK: { + return net.md_5.bungee.api.ChatColor.BLACK; + } + case DARK_BLUE: { + return net.md_5.bungee.api.ChatColor.DARK_BLUE; + } + case DARK_GREEN: { + return net.md_5.bungee.api.ChatColor.DARK_GREEN; + } + case DARK_AQUA: { + return net.md_5.bungee.api.ChatColor.DARK_AQUA; + } + case DARK_RED: { + return net.md_5.bungee.api.ChatColor.DARK_RED; + } + case DARK_PURPLE: { + return net.md_5.bungee.api.ChatColor.DARK_PURPLE; + } + case GOLD: { + return net.md_5.bungee.api.ChatColor.GOLD; + } + case GRAY: { + return net.md_5.bungee.api.ChatColor.GRAY; + } + case DARK_GRAY: { + return net.md_5.bungee.api.ChatColor.DARK_GRAY; + } + case BLUE: { + return net.md_5.bungee.api.ChatColor.BLUE; + } + case GREEN: { + return net.md_5.bungee.api.ChatColor.GREEN; + } + case AQUA: { + return net.md_5.bungee.api.ChatColor.AQUA; + } + case RED: { + return net.md_5.bungee.api.ChatColor.RED; + } + case LIGHT_PURPLE: { + return net.md_5.bungee.api.ChatColor.LIGHT_PURPLE; + } + case YELLOW: { + return net.md_5.bungee.api.ChatColor.YELLOW; + } + case WHITE: { + return net.md_5.bungee.api.ChatColor.WHITE; + } + case MAGIC: { + return net.md_5.bungee.api.ChatColor.MAGIC; + } + case BOLD: { + return net.md_5.bungee.api.ChatColor.BOLD; + } + case STRIKETHROUGH: { + return net.md_5.bungee.api.ChatColor.STRIKETHROUGH; + } + case UNDERLINE: { + return net.md_5.bungee.api.ChatColor.UNDERLINE; + } + case ITALIC: { + return net.md_5.bungee.api.ChatColor.ITALIC; + } + case RESET: { + return net.md_5.bungee.api.ChatColor.RESET; + } + default: { + throw new IllegalArgumentException("Unrecognised Bukkit colour " + color.name() + "."); + } + } + } +} diff --git a/src/LorexMC/us/utils/UUIDFetcher.java b/src/LorexMC/us/utils/UUIDFetcher.java new file mode 100644 index 0000000..a236ff6 --- /dev/null +++ b/src/LorexMC/us/utils/UUIDFetcher.java @@ -0,0 +1,97 @@ +package LorexMC.us.utils; + +import java.util.concurrent.*; +import org.json.simple.parser.*; +import com.google.common.collect.*; +import java.nio.charset.*; +import org.json.simple.*; +import java.io.*; +import java.net.*; +import java.nio.*; +import java.util.*; + +public class UUIDFetcher implements Callable> { + private static final double PROFILES_PER_REQUEST = 100.0; + private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; + private final JSONParser jsonParser; + private final List names; + private final boolean rateLimiting; + + public UUIDFetcher(final List names) { + this(names, true); + } + + public UUIDFetcher(final List names, final boolean rateLimiting) { + this.jsonParser = new JSONParser(); + this.names = ImmutableList.copyOf((Collection) names); + this.rateLimiting = rateLimiting; + } + + @Override + public Map call() throws Exception { + final Map uuidMap = new HashMap(); + for (int requests = (int) Math.ceil(this.names.size() / 100.0), i = 0; i < requests; ++i) { + final HttpURLConnection connection = createConnection(); + final String body = JSONArray + .toJSONString(this.names.subList(i * 100, Math.min((i + 1) * 100, this.names.size()))); + writeBody(connection, body); + final JSONArray array = (JSONArray) this.jsonParser + .parse(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); + for (final Object profile : array) { + final JSONObject jsonProfile = (JSONObject) profile; + final String id = (String) jsonProfile.get("id"); + final String name = (String) jsonProfile.get("name"); + final UUID uuid = getUUID(id); + uuidMap.put(name, uuid); + } + if (this.rateLimiting && i != requests - 1) { + Thread.sleep(100L); + } + } + return uuidMap; + } + + private static void writeBody(final HttpURLConnection connection, final String body) throws Exception { + final OutputStream stream = connection.getOutputStream(); + stream.write(body.getBytes(StandardCharsets.UTF_8)); + stream.flush(); + stream.close(); + } + + private static HttpURLConnection createConnection() throws Exception { + final URL url = new URL("https://api.mojang.com/profiles/minecraft"); + final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + return connection; + } + + private static UUID getUUID(final String id) { + return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + + id.substring(16, 20) + "-" + id.substring(20, 32)); + } + + public static byte[] toBytes(final UUID uuid) { + final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); + byteBuffer.putLong(uuid.getMostSignificantBits()); + byteBuffer.putLong(uuid.getLeastSignificantBits()); + return byteBuffer.array(); + } + + public static UUID fromBytes(final byte[] array) { + if (array.length != 16) { + throw new IllegalArgumentException("Illegal byte array length: " + array.length); + } + final ByteBuffer byteBuffer = ByteBuffer.wrap(array); + final long mostSignificant = byteBuffer.getLong(); + final long leastSignificant = byteBuffer.getLong(); + return new UUID(mostSignificant, leastSignificant); + } + + public static UUID getUUIDOf(final String name) throws Exception { + return new UUIDFetcher(Collections.singletonList(name)).call().get(name); + } +} diff --git a/src/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.java b/src/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.java new file mode 100644 index 0000000..4d71d7d --- /dev/null +++ b/src/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.java @@ -0,0 +1,48 @@ +package LorexMC.us.utils.compat.com.google.common.collect; + +import com.google.common.annotations.*; +import java.util.*; +import javax.annotation.*; +import com.google.common.base.*; +import com.google.common.collect.*; + +@GwtCompatible(emulated = true) +public abstract class FluentIterableCompat implements Iterable { + private final Iterable iterable; + + FluentIterableCompat(final Iterable iterable) { + this.iterable = (Iterable) Preconditions.checkNotNull((Object) iterable); + } + + @CheckReturnValue + public static FluentIterableCompat from(final Iterable iterable) { + return (iterable instanceof FluentIterableCompat) ? ((FluentIterableCompat) iterable) + : new FluentIterableCompat(iterable) { + @Override + public Iterator iterator() { + return iterable.iterator(); + } + }; + } + + @CheckReturnValue + @Override + public String toString() { + return Iterables.toString(this.iterable); + } + + @CheckReturnValue + public final FluentIterableCompat filter(final Predicate predicate) { + return from((Iterable) Iterables.filter((Iterable) this.iterable, (Predicate) predicate)); + } + + @CheckReturnValue + public final FluentIterableCompat transform(final Function function) { + return from((Iterable) Iterables.transform((Iterable) this.iterable, (Function) function)); + } + + @CheckReturnValue + public final ImmutableList toList() { + return ImmutableList.copyOf((Iterable) this.iterable); + } +} diff --git a/src/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.java b/src/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.java new file mode 100644 index 0000000..52956e7 --- /dev/null +++ b/src/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.java @@ -0,0 +1,20 @@ +package LorexMC.us.utils.compat.com.google.common.collect; + +import com.google.common.base.*; +import javax.annotation.*; + +public class GuavaCompat { + public static > Optional getIfPresent(final Class enumClass, final String value) { + Preconditions.checkNotNull((Object) enumClass); + Preconditions.checkNotNull((Object) value); + try { + return Optional.of(Enum.valueOf(enumClass, value)); + } catch (IllegalArgumentException iae) { + return Optional.absent(); + } + } + + public static T firstNonNull(@Nullable final T first, @Nullable final T second) { + return (first != null) ? first : Preconditions.checkNotNull(second); + } +} diff --git a/src/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.java b/src/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.java new file mode 100644 index 0000000..41800b7 --- /dev/null +++ b/src/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.java @@ -0,0 +1,12 @@ +package LorexMC.us.utils.internal.com.bruce.base; + +import org.bukkit.*; + +public final class BaseConstants { + public static final String PLAYER_WITH_NAME_OR_UUID_NOT_FOUND; + + static { + PLAYER_WITH_NAME_OR_UUID_NOT_FOUND = ChatColor.GOLD + "Player with name or UUID '" + ChatColor.WHITE + "%1$s" + + ChatColor.GOLD + "' not found."; + } +} diff --git a/src/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.java b/src/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.java new file mode 100644 index 0000000..c1c4f8d --- /dev/null +++ b/src/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.java @@ -0,0 +1,76 @@ +package LorexMC.us.utils.internal.com.bruce.base; + +import java.util.*; +import org.bukkit.plugin.java.*; + +import LorexMC.us.utils.PersistableLocation; +import LorexMC.us.utils.SignHandler; +import LorexMC.us.utils.other.chat.*; +import LorexMC.us.utils.other.cuboid.*; +import LorexMC.us.utils.other.itemdb.*; +import me.bruce.factions.listener.PlayTimeManager; + +import org.bukkit.configuration.serialization.*; + +import java.io.*; + +public class BasePlugin { + private Random random; + private static ItemDb itemDb; + private SignHandler signHandler; + private static BasePlugin plugin; + private JavaPlugin javaPlugin; + + private BasePlugin() { + this.random = new Random(); + } + + public void init(final JavaPlugin plugin) { + this.javaPlugin = plugin; + ConfigurationSerialization.registerClass(PersistableLocation.class); + ConfigurationSerialization.registerClass(Cuboid.class); + ConfigurationSerialization.registerClass(NamedCuboid.class); + this.itemDb = new SimpleItemDb(plugin); + this.signHandler = new SignHandler(plugin); + try { + Lang.initialize("en_US"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void disable() { + this.signHandler.cancelTasks(null); + this.javaPlugin = null; + BasePlugin.plugin = null; + } + + public Random getRandom() { + return this.random; + } + + public static ItemDb getItemDb() { + return itemDb; + } + + public SignHandler getSignHandler() { + return this.signHandler; + } + + public static BasePlugin getPlugin() { + return BasePlugin.plugin; + } + + public JavaPlugin getJavaPlugin() { + return this.javaPlugin; + } + + static { + BasePlugin.plugin = new BasePlugin(); + } + + public PlayTimeManager getPlayTimeManager() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/LorexMC/us/utils/internal/com/bruce/base/Callback.java b/src/LorexMC/us/utils/internal/com/bruce/base/Callback.java new file mode 100644 index 0000000..419c0ab --- /dev/null +++ b/src/LorexMC/us/utils/internal/com/bruce/base/Callback.java @@ -0,0 +1,5 @@ +package LorexMC.us.utils.internal.com.bruce.base; + +public interface Callback { + void done(final V p0, final Throwable p1); +} diff --git a/src/LorexMC/us/utils/other/chat/ChatUtil.java b/src/LorexMC/us/utils/other/chat/ChatUtil.java new file mode 100644 index 0000000..fad0af5 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/ChatUtil.java @@ -0,0 +1,69 @@ +package LorexMC.us.utils.other.chat; + +import org.bukkit.potion.*; +import org.apache.commons.lang.*; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; +import org.bukkit.*; +import org.bukkit.Material; +import org.bukkit.command.*; +import org.bukkit.entity.*; +import org.bukkit.craftbukkit.v1_7_R4.entity.*; +import net.minecraft.server.v1_7_R4.*; + +public class ChatUtil { + public static String getName(final ItemStack stack) { + if (stack.tag != null && stack.tag.hasKeyOfType("display", 10)) { + final NBTTagCompound nbttagcompound = stack.tag.getCompound("display"); + if (nbttagcompound.hasKeyOfType("Name", 8)) { + return nbttagcompound.getString("Name"); + } + } + return stack.getItem().a(stack) + ".name"; + } + + public static Trans localFromItem(final org.bukkit.inventory.ItemStack stack) { + if (stack.getType() == Material.POTION && stack.getData().getData() == 0) { + final Potion potion = Potion.fromItemStack(stack); + if (potion != null) { + final PotionType type = potion.getType(); + if (type != null && type != PotionType.WATER) { + final String effectName = (potion.isSplash() ? "Splash " : "") + + WordUtils.capitalizeFully(type.name().replace('_', ' ')) + " L" + potion.getLevel(); + return fromItemStack(stack).append(" of " + effectName); + } + } + } + return fromItemStack(stack); + } + + public static Trans fromItemStack(final org.bukkit.inventory.ItemStack stack) { + final ItemStack nms = CraftItemStack.asNMSCopy(stack); + final NBTTagCompound tag = new NBTTagCompound(); + nms.save(tag); + return new Trans(getName(nms), new Object[0]).setColor(ChatColor.getByChar(nms.w().e.getChar())) + .setHover(HoverAction.SHOW_ITEM, new ChatComponentText(tag.toString())); + } + + public static void reset(final IChatBaseComponent text) { + final ChatModifier modifier = text.getChatModifier(); + modifier.a((ChatHoverable) null); + modifier.setChatClickable((ChatClickable) null); + modifier.setBold(false); + modifier.setColor(EnumChatFormat.RESET); + modifier.setItalic(false); + modifier.setRandom(false); + modifier.setStrikethrough(false); + modifier.setUnderline(false); + } + + public static void send(final CommandSender sender, final IChatBaseComponent text) { + if (sender instanceof Player) { + final Player player = (Player) sender; + final PacketPlayOutChat packet = new PacketPlayOutChat(text, true); + final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + entityPlayer.playerConnection.sendPacket(packet); + } else { + sender.sendMessage(text.c()); + } + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/ClickAction.java b/src/LorexMC/us/utils/other/chat/ClickAction.java new file mode 100644 index 0000000..f291597 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/ClickAction.java @@ -0,0 +1,18 @@ +package LorexMC.us.utils.other.chat; + +import net.minecraft.server.v1_7_R4.*; + +public enum ClickAction { + OPEN_URL(EnumClickAction.OPEN_URL), OPEN_FILE(EnumClickAction.OPEN_FILE), RUN_COMMAND( + EnumClickAction.RUN_COMMAND), SUGGEST_COMMAND(EnumClickAction.SUGGEST_COMMAND); + + private final EnumClickAction clickAction; + + private ClickAction(final EnumClickAction action) { + this.clickAction = action; + } + + public EnumClickAction getNMS() { + return this.clickAction; + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/HoverAction.java b/src/LorexMC/us/utils/other/chat/HoverAction.java new file mode 100644 index 0000000..fe7b0cd --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/HoverAction.java @@ -0,0 +1,18 @@ +package LorexMC.us.utils.other.chat; + +import net.minecraft.server.v1_7_R4.*; + +public enum HoverAction { + SHOW_TEXT(EnumHoverAction.SHOW_TEXT), SHOW_ITEM(EnumHoverAction.SHOW_ITEM), SHOW_ACHIEVEMENT( + EnumHoverAction.SHOW_ACHIEVEMENT); + + private final EnumHoverAction hoverAction; + + private HoverAction(final EnumHoverAction hoverAction) { + this.hoverAction = hoverAction; + } + + public EnumHoverAction getNMS() { + return this.hoverAction; + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/Lang.java b/src/LorexMC/us/utils/other/chat/Lang.java new file mode 100644 index 0000000..6a3cffb --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/Lang.java @@ -0,0 +1,99 @@ +package LorexMC.us.utils.other.chat; + +import java.util.*; + +import org.bukkit.*; + +import java.util.logging.*; +import java.net.*; +import java.nio.charset.*; +import java.util.regex.*; +import java.io.*; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; + +import net.minecraft.server.v1_7_R4.*; + +import com.google.common.base.*; + +import org.bukkit.enchantments.Enchantment; +import org.bukkit.potion.*; +import org.bukkit.craftbukkit.v1_7_R4.potion.*; + +@Deprecated +public class Lang { + private static final Pattern PATTERN; + private static final String HASH_17 = "03f31164d234f10a3230611656332f1756e570a9"; + private static Map translations; + + public static void initialize(final String lang) throws IOException { + Lang.translations = new HashMap(); + Bukkit.getLogger().log(Level.INFO, "Initialling"); + if ("03f31164d234f10a3230611656332f1756e570a9".length() >= 2) { + final String url = "http://resources.download.minecraft.net/" + + "03f31164d234f10a3230611656332f1756e570a9".substring(0, 2) + "/" + + "03f31164d234f10a3230611656332f1756e570a9"; + try (final BufferedReader reader = new BufferedReader( + new InputStreamReader(new URL(url).openStream(), StandardCharsets.UTF_8))) { + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + // Bukkit.getLogger().info(line); + if (line.contains("=")) { + final Matcher matcher = Lang.PATTERN.matcher(line); + if (!matcher.matches()) { + continue; + } + Lang.translations.put(matcher.group(1), matcher.group(2)); + } + } + } + } + } + + public static String translatableFromStack(final ItemStack stack) { + final net.minecraft.server.v1_7_R4.ItemStack nms = CraftItemStack.asNMSCopy(stack); + final Item item = nms.getItem(); + return item.a(nms) + ".name"; + } + + public static String fromStack(final ItemStack stack) { + final String node = translatableFromStack(stack); + return (String) MoreObjects.firstNonNull((Object) Lang.translations.get(node), (Object) node); + } + + public static String translatableFromEnchantment(final Enchantment ench) { + final net.minecraft.server.v1_7_R4.Enchantment nms = net.minecraft.server.v1_7_R4.Enchantment.byId[ench + .getId()]; + return (nms == null) ? ench.getName() : nms.a(); + } + + public static String fromEnchantment(final Enchantment enchantment) { + final String node = translatableFromEnchantment(enchantment); + final String trans = Lang.translations.get(node); + return (trans != null) ? trans : node; + } + + public static String translatableFromPotionEffectType(final PotionEffectType effectType) { + final CraftPotionEffectType craftType = (CraftPotionEffectType) PotionEffectType.getById(effectType.getId()); + return craftType.getHandle().a(); + } + + public static String fromPotionEffectType(final PotionEffectType effectType) { + final String node = translatableFromPotionEffectType(effectType); + final String val = Lang.translations.get(node); + if (val == null) { + return node; + } + return val; + } + + public static String translate(final String key, final Object... args) { + return String.format(Lang.translations.get(key), args); + } + + static { + PATTERN = Pattern.compile("^\\s*([\\w\\d\\.]+)\\s*=\\s*(.*)\\s*$"); + } +} diff --git a/src/LorexMC/us/utils/other/chat/Text.java b/src/LorexMC/us/utils/other/chat/Text.java new file mode 100644 index 0000000..334d7d8 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/Text.java @@ -0,0 +1,133 @@ +package LorexMC.us.utils.other.chat; + +import org.bukkit.inventory.ItemStack; + +import net.minecraft.server.v1_7_R4.*; +import org.bukkit.command.*; +import org.bukkit.*; +import org.bukkit.entity.*; + +public class Text extends ChatComponentText { + public Text() { + super(""); + } + + public Text(final String string) { + super(string); + } + + public Text(final Object object) { + super(String.valueOf(object)); + } + + public static Trans fromItemStack(final ItemStack stack) { + return ChatUtil.fromItemStack(stack); + } + + public Text append(final Object object) { + return this.append(String.valueOf(object)); + } + + public Text append(final String text) { + return (Text) this.a(text); + } + + public Text setClick1(ClickAction action, String value) { + getChatModifier().setChatClickable(new ChatClickable(action.getNMS(), value)); + return this; + } + + public Text append(final IChatBaseComponent node) { + return (Text) this.addSibling(node); + } + + public Text append(final IChatBaseComponent... nodes) { + for (final IChatBaseComponent node : nodes) { + this.addSibling(node); + } + return this; + } + + public Text localText(final ItemStack stack) { + return this.append(ChatUtil.localFromItem(stack)); + } + + public Text appendItem(final ItemStack stack) { + return this.append(ChatUtil.fromItemStack(stack)); + } + + public Text setBold(final boolean bold) { + this.getChatModifier().setBold(bold); + return this; + } + + public Text setItalic(final boolean italic) { + this.getChatModifier().setItalic(italic); + return this; + } + + public Text setUnderline(final boolean underline) { + this.getChatModifier().setUnderline(underline); + return this; + } + + public Text setRandom(final boolean random) { + this.getChatModifier().setRandom(random); + return this; + } + + public Text setStrikethrough(final boolean strikethrough) { + this.getChatModifier().setStrikethrough(strikethrough); + return this; + } + + public Text setColor(final ChatColor color) { + this.getChatModifier().setColor(EnumChatFormat.valueOf(color.name())); + return this; + } + + public Text setClick(final ClickAction action, final String value) { + this.getChatModifier().setChatClickable(new ChatClickable(action.getNMS(), value)); + return this; + } + + public Text setHover(final HoverAction action, final IChatBaseComponent value) { + this.getChatModifier().a(new ChatHoverable(action.getNMS(), value)); + return this; + } + + public Text setHoverText(final String text) { + return this.setHover(HoverAction.SHOW_TEXT, new Text(text)); + } + + public Text reset() { + ChatUtil.reset(this); + return this; + } + + @Override + public IChatBaseComponent f() { + return this.h(); + } + + public String toRawText() { + return this.c(); + } + + public void send(final CommandSender sender) { + ChatUtil.send(sender, this); + } + + public void broadcast() { + this.broadcast(null); + } + + public void broadcast(final String permission) { + for (final Player player : Bukkit.getOnlinePlayers()) { + if (permission == null || player.hasPermission(permission)) { + this.send(player); + } + } + this.send(Bukkit.getConsoleSender()); + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/Trans.java b/src/LorexMC/us/utils/other/chat/Trans.java new file mode 100644 index 0000000..0bbf3f0 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/Trans.java @@ -0,0 +1,109 @@ +package LorexMC.us.utils.other.chat; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.*; +import net.minecraft.server.v1_7_R4.*; +import org.bukkit.command.*; + +public class Trans extends ChatMessage { + public Trans() { + super("", new Object[0]); + } + + public Trans(final String string, final Object... objects) { + super(string, objects); + } + + public static Trans fromItemStack(final ItemStack stack) { + return ChatUtil.fromItemStack(stack); + } + + @Override + public IChatBaseComponent f() { + return this.h(); + } + + public Trans append(final Object object) { + return this.append(String.valueOf(object)); + } + + public Trans append(final String text) { + return (Trans) this.a(text); + } + + public Trans append(final IChatBaseComponent node) { + return (Trans) this.addSibling(node); + } + + public Trans append(final IChatBaseComponent... nodes) { + for (final IChatBaseComponent node : nodes) { + this.addSibling(node); + } + return this; + } + + public Trans appendItem(final ItemStack stack) { + return this.append(ChatUtil.fromItemStack(stack)); + } + + public Trans localText(final ItemStack stack) { + return this.append(ChatUtil.localFromItem(stack)); + } + + public Trans setBold(final boolean bold) { + this.getChatModifier().setBold(bold); + return this; + } + + public Trans setItalic(final boolean italic) { + this.getChatModifier().setItalic(italic); + return this; + } + + public Trans setUnderline(final boolean underline) { + this.getChatModifier().setUnderline(underline); + return this; + } + + public Trans setRandom(final boolean random) { + this.getChatModifier().setRandom(random); + return this; + } + + public Trans setStrikethrough(final boolean strikethrough) { + this.getChatModifier().setStrikethrough(strikethrough); + return this; + } + + public Trans setColor(final ChatColor color) { + this.getChatModifier().setColor(EnumChatFormat.valueOf(color.name())); + return this; + } + + public Trans setClick(final ClickAction action, final String value) { + this.getChatModifier().setChatClickable(new ChatClickable(action.getNMS(), value)); + return this; + } + + public Trans setHover(final HoverAction action, final IChatBaseComponent value) { + this.getChatModifier().a(new ChatHoverable(action.getNMS(), value)); + return this; + } + + public Trans setHoverText(final String text) { + return this.setHover(HoverAction.SHOW_TEXT, new Text(text)); + } + + public Trans reset() { + ChatUtil.reset(this); + return this; + } + + public String toRawText() { + return this.c(); + } + + public void send(final CommandSender sender) { + ChatUtil.send(sender, this); + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/command/ArgumentExecutor.java b/src/LorexMC/us/utils/other/command/ArgumentExecutor.java new file mode 100644 index 0000000..d44dda0 --- /dev/null +++ b/src/LorexMC/us/utils/other/command/ArgumentExecutor.java @@ -0,0 +1,107 @@ +package LorexMC.us.utils.other.command; + +import com.google.common.collect.*; + +import LorexMC.us.utils.*; + +import java.util.*; +import org.bukkit.command.*; +import org.bukkit.*; +import org.apache.commons.lang3.text.*; + +public abstract class ArgumentExecutor implements CommandExecutor, TabCompleter { + protected final List arguments; + protected final String label; + + public ArgumentExecutor(final String label) { + this.arguments = new ArrayList(); + this.label = label; + } + + public boolean containsArgument(final CommandArgument argument) { + return this.arguments.contains(argument); + } + + public void addArgument(final CommandArgument argument) { + this.arguments.add(argument); + } + + public void removeArgument(final CommandArgument argument) { + this.arguments.remove(argument); + } + + public CommandArgument getArgument(final String id) { + for (final CommandArgument argument : this.arguments) { + final String name = argument.getName(); + if (name.equalsIgnoreCase(id) || Arrays.asList(argument.getAliases()).contains(id.toLowerCase())) { + return argument; + } + } + return null; + } + + public String getLabel() { + return this.label; + } + + public List getArguments() { + return ImmutableList.copyOf((Collection) this.arguments); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + sender.sendMessage(String.valueOf(ChatColor.GRAY.toString()) + ChatColor.STRIKETHROUGH + + "----------------------------------------------------"); + sender.sendMessage(String.valueOf(ChatColor.GOLD.toString()) + ChatColor.BOLD + WordUtils + .capitalizeFully(String.valueOf(this.label) + ChatColor.GOLD + ChatColor.BOLD + " Help")); + sender.sendMessage(""); + for (final CommandArgument argument : this.arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + sender.sendMessage( + ChatColor.GOLD + argument.getUsage(label) + " §7» §f" + argument.getDescription() + '.'); + } + } + sender.sendMessage(String.valueOf(ChatColor.GRAY.toString()) + ChatColor.STRIKETHROUGH + + "----------------------------------------------------"); + return true; + } + final CommandArgument argument2 = this.getArgument(args[0]); + final String permission2 = (argument2 == null) ? null : argument2.getPermission(); + if (argument2 == null || (permission2 != null && !sender.hasPermission(permission2))) { + sender.sendMessage(ChatColor.RED + WordUtils.capitalizeFully(this.label) + "Error."); + return true; + } + argument2.onCommand(sender, command, label, args); + return true; + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + List results = new ArrayList(); + if (args.length < 2) { + for (final CommandArgument argument : this.arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + results.add(argument.getName()); + } + } + } else { + final CommandArgument argument2 = this.getArgument(args[0]); + if (argument2 == null) { + return results; + } + final String permission2 = argument2.getPermission(); + if (permission2 == null || sender.hasPermission(permission2)) { + results = argument2.onTabComplete(sender, command, label, args); + if (results == null) { + return null; + } + } + } + return BukkitUtils.getCompletions(args, results); + } +} diff --git a/src/LorexMC/us/utils/other/command/CommandArgument.java b/src/LorexMC/us/utils/other/command/CommandArgument.java new file mode 100644 index 0000000..42866e2 --- /dev/null +++ b/src/LorexMC/us/utils/other/command/CommandArgument.java @@ -0,0 +1,114 @@ +package LorexMC.us.utils.other.command; + +import org.apache.commons.lang3.*; +import org.bukkit.command.*; +import java.util.*; + +public abstract class CommandArgument { + private final String name; + protected boolean isPlayerOnly; + protected String description; + protected String permission; + protected String[] aliases; + + public CommandArgument(final String name, final String description) { + this(name, description, (String) null); + } + + public CommandArgument(final String name, final String description, final String permission) { + this(name, description, permission, ArrayUtils.EMPTY_STRING_ARRAY); + } + + public CommandArgument(final String name, final String description, final String[] aliases) { + this(name, description, null, aliases); + } + + public CommandArgument(final String name, final String description, final String permission, + final String[] aliases) { + this.isPlayerOnly = false; + this.name = name; + this.description = description; + this.permission = permission; + this.aliases = Arrays.copyOf(aliases, aliases.length); + } + + public final String getName() { + return this.name; + } + + public boolean isPlayerOnly() { + return this.isPlayerOnly; + } + + public final String getDescription() { + return this.description; + } + + public final String getPermission() { + return this.permission; + } + + public final String[] getAliases() { + if (this.aliases == null) { + this.aliases = ArrayUtils.EMPTY_STRING_ARRAY; + } + return Arrays.copyOf(this.aliases, this.aliases.length); + } + + public abstract String getUsage(final String p0); + + public abstract boolean onCommand(final CommandSender p0, final Command p1, final String p2, final String[] p3); + + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + return Collections.emptyList(); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof CommandArgument)) { + return false; + } + final CommandArgument that = (CommandArgument) o; + Label_0054: { + if (this.name != null) { + if (this.name.equals(that.name)) { + break Label_0054; + } + } else if (that.name == null) { + break Label_0054; + } + return false; + } + Label_0087: { + if (this.description != null) { + if (this.description.equals(that.description)) { + break Label_0087; + } + } else if (that.description == null) { + break Label_0087; + } + return false; + } + if (this.permission != null) { + if (this.permission.equals(that.permission)) { + return Arrays.equals(this.aliases, that.aliases); + } + } else if (that.permission == null) { + return Arrays.equals(this.aliases, that.aliases); + } + return false; + } + + @Override + public int hashCode() { + int result = (this.name != null) ? this.name.hashCode() : 0; + result = 31 * result + ((this.description != null) ? this.description.hashCode() : 0); + result = 31 * result + ((this.permission != null) ? this.permission.hashCode() : 0); + result = 31 * result + ((this.aliases != null) ? Arrays.hashCode(this.aliases) : 0); + return result; + } +} diff --git a/src/LorexMC/us/utils/other/command/CommandWrapper.java b/src/LorexMC/us/utils/other/command/CommandWrapper.java new file mode 100644 index 0000000..d367d25 --- /dev/null +++ b/src/LorexMC/us/utils/other/command/CommandWrapper.java @@ -0,0 +1,97 @@ +package LorexMC.us.utils.other.command; + +import org.bukkit.command.*; +import org.bukkit.entity.*; + +import LorexMC.us.utils.BukkitUtils; +import org.bukkit.*; +import org.apache.commons.lang3.text.*; +import java.util.*; +import java.io.*; + +public class CommandWrapper implements CommandExecutor, TabCompleter { + private final Collection arguments; + + public CommandWrapper(final Collection arguments) { + this.arguments = arguments; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + printUsage(sender, label, this.arguments); + return true; + } + final CommandArgument argument = matchArgument(args[0], sender, this.arguments); + if (argument == null) { + printUsage(sender, label, this.arguments); + return true; + } + return argument.onCommand(sender, command, label, args); + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (!(sender instanceof Player)) { + return Collections.emptyList(); + } + List results; + if (args.length == 1) { + results = getAccessibleArgumentNames(sender, this.arguments); + } else { + final CommandArgument argument = matchArgument(args[0], sender, this.arguments); + if (argument == null) { + return Collections.emptyList(); + } + results = argument.onTabComplete(sender, command, label, args); + if (results == null) { + return null; + } + } + return BukkitUtils.getCompletions(args, results); + } + + public static void printUsage(final CommandSender sender, final String label, + final Collection arguments) { + sender.sendMessage(ChatColor.DARK_AQUA + "*** " + WordUtils.capitalizeFully(label) + " Help ***"); + for (final CommandArgument argument : arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + sender.sendMessage(ChatColor.GRAY + argument.getUsage(label) + " - " + argument.getDescription()); + } + } + } + + public static CommandArgument matchArgument(final String id, final CommandSender sender, + final Collection arguments) { + for (final CommandArgument argument : arguments) { + final String permission = argument.getPermission(); + if ((permission == null || sender.hasPermission(permission)) + && (argument.getName().equalsIgnoreCase(id) || Arrays.asList(argument.getAliases()).contains(id))) { + return argument; + } + } + return null; + } + + public static List getAccessibleArgumentNames(final CommandSender sender, + final Collection arguments) { + final List results = new ArrayList(); + for (final CommandArgument argument : arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + results.add(argument.getName()); + } + } + return results; + } + + public static class ArgumentComparator implements Comparator, Serializable { + @Override + public int compare(final CommandArgument primaryArgument, final CommandArgument secondaryArgument) { + return secondaryArgument.getName().compareTo(primaryArgument.getName()); + } + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CoordinatePair.java b/src/LorexMC/us/utils/other/cuboid/CoordinatePair.java new file mode 100644 index 0000000..4fc7344 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CoordinatePair.java @@ -0,0 +1,69 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.block.*; +import org.bukkit.*; + +public class CoordinatePair { + private final String worldName; + private final int x; + private final int z; + + public CoordinatePair(final Block block) { + this(block.getWorld(), block.getX(), block.getZ()); + } + + public CoordinatePair(final World world, final int x, final int z) { + this.worldName = world.getName(); + this.x = x; + this.z = z; + } + + public World getWorld() { + return Bukkit.getWorld(this.worldName); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof CoordinatePair)) { + return false; + } + final CoordinatePair that = (CoordinatePair) o; + if (this.x != that.x) { + return false; + } + if (this.z != that.z) { + return false; + } + if (this.worldName != null) { + if (!this.worldName.equals(that.worldName)) { + return false; + } + } else if (that.worldName != null) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = (this.worldName != null) ? this.worldName.hashCode() : 0; + result = 31 * result + this.x; + result = 31 * result + this.z; + return result; + } + + public String getWorldName() { + return this.worldName; + } + + public int getX() { + return this.x; + } + + public int getZ() { + return this.z; + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/Cuboid.java b/src/LorexMC/us/utils/other/cuboid/Cuboid.java new file mode 100644 index 0000000..6905044 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/Cuboid.java @@ -0,0 +1,519 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.block.*; +import org.bukkit.configuration.serialization.*; + +import com.google.common.base.*; + +import org.bukkit.util.Vector; +import org.bukkit.entity.*; + +import java.util.*; + +import org.bukkit.*; + +public class Cuboid implements Iterable, Cloneable, ConfigurationSerializable { + protected final String worldName; + protected int x1; + protected int y1; + protected int z1; + protected int x2; + protected int y2; + protected int z2; + private static final int CHUNK_SIZE = 16; + + public Cuboid(final Map map) { + this.worldName = (String) map.get("worldName"); + this.x1 = (int) map.get("x1"); + this.y1 = (int) map.get("y1"); + this.z1 = (int) map.get("z1"); + this.x2 = (int) map.get("x2"); + this.y2 = (int) map.get("y2"); + this.z2 = (int) map.get("z2"); + } + + public Cuboid(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + this(((World) Preconditions.checkNotNull((Object) world)).getName(), x1, y1, z1, x2, y2, z2); + } + + private Cuboid(final String worldName, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + Preconditions.checkNotNull((Object) worldName, (Object) "World name cannot be null"); + this.worldName = worldName; + this.x1 = Math.min(x1, x2); + this.y1 = Math.min(y1, y2); + this.z1 = Math.min(z1, z2); + this.x2 = Math.max(x1, x2); + this.y2 = Math.max(y1, y2); + this.z2 = Math.max(z1, z2); + } + + public Cuboid(final Location first, final Location second) { + Preconditions.checkNotNull((Object) first, (Object) "Location 1 cannot be null"); + Preconditions.checkNotNull((Object) second, (Object) "Location 2 cannot be null"); + Preconditions.checkArgument(first.getWorld().equals(second.getWorld()), "Locations must be on the same world"); + this.worldName = first.getWorld().getName(); + this.x1 = Math.min(first.getBlockX(), second.getBlockX()); + this.y1 = Math.min(first.getBlockY(), second.getBlockY()); + this.z1 = Math.min(first.getBlockZ(), second.getBlockZ()); + this.x2 = Math.max(first.getBlockX(), second.getBlockX()); + this.y2 = Math.max(first.getBlockY(), second.getBlockY()); + this.z2 = Math.max(first.getBlockZ(), second.getBlockZ()); + } + + public Cuboid(final Location location) { + this(location, location); + } + + public Cuboid(final Cuboid other) { + this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2); + } + + @Override + public Map serialize() { + final Map map = new LinkedHashMap(); + map.put("worldName", this.worldName); + map.put("x1", this.x1); + map.put("y1", this.y1); + map.put("z1", this.z1); + map.put("x2", this.x2); + map.put("y2", this.y2); + map.put("z2", this.z2); + return map; + } + + public boolean hasBothPositionsSet() { + return this.getMinimumPoint() != null && this.getMaximumPoint() != null; + } + + public int getMinimumX() { + return Math.min(this.x1, this.x2); + } + + public int getMinimumZ() { + return Math.min(this.z1, this.z2); + } + + public int getMaximumX() { + return Math.max(this.x1, this.x2); + } + + public int getMaximumZ() { + return Math.max(this.z1, this.z2); + } + + public List edges() { + return this.edges(-1, -1, -1, -1); + } + + public List edges(final int fixedMinX, final int fixedMaxX, final int fixedMinZ, final int fixedMaxZ) { + final Vector v1 = this.getMinimumPoint().toVector(); + final Vector v2 = this.getMaximumPoint().toVector(); + final int minX = v1.getBlockX(); + final int maxX = v2.getBlockX(); + final int minZ = v1.getBlockZ(); + final int maxZ = v2.getBlockZ(); + int capacity = (maxX - minX) * 4 + (maxZ - minZ) * 4; + capacity += 4; + final List result = new ArrayList(capacity); + if (capacity <= 0) { + return result; + } + final int minY = v1.getBlockY(); + final int maxY = v1.getBlockY(); + for (int x = minX; x <= maxX; ++x) { + result.add(new Vector(x, minY, minZ)); + result.add(new Vector(x, minY, maxZ)); + result.add(new Vector(x, maxY, minZ)); + result.add(new Vector(x, maxY, maxZ)); + } + for (int z = minZ; z <= maxZ; ++z) { + result.add(new Vector(minX, minY, z)); + result.add(new Vector(minX, maxY, z)); + result.add(new Vector(maxX, minY, z)); + result.add(new Vector(maxX, maxY, z)); + } + return result; + } + + public Set getPlayers() { + final Set players = new HashSet(); + for (final Player player : Bukkit.getOnlinePlayers()) { + if (this.contains(player)) { + players.add(player); + } + } + return players; + } + + public Location getLowerNE() { + return new Location(this.getWorld(), this.x1, this.y1, this.z1); + } + + public Location getUpperSW() { + return new Location(this.getWorld(), this.x2, this.y2, this.z2); + } + + public Location getCenter() { + final int x1 = this.x2 + 1; + final int y1 = this.y2 + 1; + final int z1 = this.z2 + 1; + return new Location(this.getWorld(), this.x1 + (x1 - this.x1) / 2.0, this.y1 + (y1 - this.y1) / 2.0, + this.z1 + (z1 - this.z1) / 2.0); + } + + public String getWorldName() { + return this.worldName; + } + + public World getWorld() { + return Bukkit.getWorld(this.worldName); + } + + public int getSizeX() { + return this.x2 - this.x1 + 1; + } + + public int getSizeY() { + return this.y2 - this.y1 + 1; + } + + public int getSizeZ() { + return this.z2 - this.z1 + 1; + } + + public int getX1() { + return this.x1; + } + + public void setX1(final int x1) { + this.x1 = x1; + } + + public int getY1() { + return this.y1; + } + + public void setY1(final int y1) { + this.y1 = y1; + } + + public int getZ1() { + return this.z1; + } + + public void setZ1(final int z1) { + this.z1 = z1; + } + + public int getX2() { + return this.x2; + } + + public int getY2() { + return this.y2; + } + + public void setY2(final int y2) { + this.y2 = y2; + } + + public int getZ2() { + return this.z2; + } + + public Location[] getCornerLocations() { + final Location[] result = new Location[8]; + final Block[] cornerBlocks = this.getCornerBlocks(); + for (int i = 0; i < cornerBlocks.length; ++i) { + result[i] = cornerBlocks[i].getLocation(); + } + return result; + } + + public Block[] getCornerBlocks() { + final Block[] result = new Block[8]; + final World world = this.getWorld(); + result[0] = world.getBlockAt(this.x1, this.y1, this.z1); + result[1] = world.getBlockAt(this.x1, this.y1, this.z2); + result[2] = world.getBlockAt(this.x1, this.y2, this.z1); + result[3] = world.getBlockAt(this.x1, this.y2, this.z2); + result[4] = world.getBlockAt(this.x2, this.y1, this.z1); + result[5] = world.getBlockAt(this.x2, this.y1, this.z2); + result[6] = world.getBlockAt(this.x2, this.y2, this.z1); + result[7] = world.getBlockAt(this.x2, this.y2, this.z2); + return result; + } + + public Cuboid shift(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + return this.expand(direction, amount).expand(direction.opposite(), -amount); + } + + public Cuboid inset(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + return this.outset(direction, -amount); + } + + public Cuboid expand(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + switch (direction) { + case NORTH: { + return new Cuboid(this.worldName, this.x1 - amount, this.y1, this.z1, this.x2, this.y2, this.z2); + } + case SOUTH: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2 + amount, this.y2, this.z2); + } + case EAST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1 - amount, this.x2, this.y2, this.z2); + } + case WEST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z2 + amount); + } + case DOWN: { + return new Cuboid(this.worldName, this.x1, this.y1 - amount, this.z1, this.x2, this.y2, this.z2); + } + case UP: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2 + amount, this.z2); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public Cuboid outset(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + switch (direction) { + case HORIZONTAL: { + return this.expand(CuboidDirection.NORTH, amount).expand(CuboidDirection.SOUTH, amount) + .expand(CuboidDirection.EAST, amount).expand(CuboidDirection.WEST, amount); + } + case VERTICAL: { + return this.expand(CuboidDirection.DOWN, amount).expand(CuboidDirection.UP, amount); + } + case BOTH: { + return this.outset(CuboidDirection.HORIZONTAL, amount).outset(CuboidDirection.VERTICAL, amount); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public boolean contains(final Cuboid cuboid) { + return this.contains(cuboid.getMinimumPoint()) || this.contains(cuboid.getMaximumPoint()); + } + + public boolean contains(final Player player) { + return this.contains(player.getLocation()); + } + + public boolean contains(final World world, final int x, final int z) { + return (world == null || this.getWorld().equals(world)) && x >= this.x1 && x <= this.x2 && z >= this.z1 + && z <= this.z2; + } + + public boolean contains(final int x, final int y, final int z) { + return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2; + } + + public boolean contains(final Block block) { + return this.contains(block.getLocation()); + } + + public boolean contains(final Location location) { + if (location == null || this.worldName == null) { + return false; + } + final World world = location.getWorld(); + return world != null && this.worldName.equals(location.getWorld().getName()) + && this.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + + public int getVolume() { + return this.getSizeX() * this.getSizeY() * this.getSizeZ(); + } + + public int getArea() { + final Location min = this.getMinimumPoint(); + final Location max = this.getMaximumPoint(); + return (max.getBlockX() - min.getBlockX() + 1) * (max.getBlockZ() - min.getBlockZ() + 1); + } + + public byte getAverageLightLevel() { + long total = 0L; + int count = 0; + for (final Block block : this) { + if (block.isEmpty()) { + total += block.getLightLevel(); + ++count; + } + } + return (count > 0) ? ((byte) (total / count)) : 0; + } + + public Location getMinimumPoint() { + return new Location(this.getWorld(), Math.min(this.x1, this.x2), Math.min(this.y1, this.y2), + Math.min(this.z1, this.z2)); + } + + public Location getMaximumPoint() { + return new Location(this.getWorld(), Math.max(this.x1, this.x2), Math.max(this.y1, this.y2), + Math.max(this.z1, this.z2)); + } + + public int getWidth() { + return this.getMaximumPoint().getBlockX() - this.getMinimumPoint().getBlockX(); + } + + public int getHeight() { + return this.getMaximumPoint().getBlockY() - this.getMinimumPoint().getBlockY(); + } + + public int getLength() { + return this.getMaximumPoint().getBlockZ() - this.getMinimumPoint().getBlockZ(); + } + + public Cuboid contract() { + return this.contract(CuboidDirection.DOWN).contract(CuboidDirection.SOUTH).contract(CuboidDirection.EAST) + .contract(CuboidDirection.UP).contract(CuboidDirection.NORTH).contract(CuboidDirection.WEST); + } + + public Cuboid contract(final CuboidDirection direction) { + Cuboid face = this.getFace(direction.opposite()); + switch (direction) { + case DOWN: { + while (face.containsOnly(Material.AIR) && face.y1 > this.y1) { + face = face.shift(CuboidDirection.DOWN, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, face.y2, this.z2); + } + case UP: { + while (face.containsOnly(Material.AIR) && face.y2 < this.y2) { + face = face.shift(CuboidDirection.UP, 1); + } + return new Cuboid(this.worldName, this.x1, face.y1, this.z1, this.x2, this.y2, this.z2); + } + case NORTH: { + while (face.containsOnly(Material.AIR) && face.x1 > this.x1) { + face = face.shift(CuboidDirection.NORTH, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, face.x2, this.y2, this.z2); + } + case SOUTH: { + while (face.containsOnly(Material.AIR) && face.x2 < this.x2) { + face = face.shift(CuboidDirection.SOUTH, 1); + } + return new Cuboid(this.worldName, face.x1, this.y1, this.z1, this.x2, this.y2, this.z2); + } + case EAST: { + while (face.containsOnly(Material.AIR) && face.z1 > this.z1) { + face = face.shift(CuboidDirection.EAST, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, face.z2); + } + case WEST: { + while (face.containsOnly(Material.AIR) && face.z2 < this.z2) { + face = face.shift(CuboidDirection.WEST, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, face.z1, this.x2, this.y2, this.z2); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public Cuboid getFace(final CuboidDirection direction) { + switch (direction) { + case DOWN: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y1, this.z2); + } + case UP: { + return new Cuboid(this.worldName, this.x1, this.y2, this.z1, this.x2, this.y2, this.z2); + } + case NORTH: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x1, this.y2, this.z2); + } + case SOUTH: { + return new Cuboid(this.worldName, this.x2, this.y1, this.z1, this.x2, this.y2, this.z2); + } + case EAST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z1); + } + case WEST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z2, this.x2, this.y2, this.z2); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public boolean containsOnly(final Material material) { + for (final Block block : this) { + if (block.getType() != material) { + return false; + } + } + return true; + } + + public Cuboid getBoundingCuboid(final Cuboid other) { + if (other == null) { + return this; + } + final int xMin = Math.min(this.x1, other.x1); + final int yMin = Math.min(this.y1, other.y1); + final int zMin = Math.min(this.z1, other.z1); + final int xMax = Math.max(this.x2, other.x2); + final int yMax = Math.max(this.y2, other.y2); + final int zMax = Math.max(this.z2, other.z2); + return new Cuboid(this.worldName, xMin, yMin, zMin, xMax, yMax, zMax); + } + + public Block getRelativeBlock(final int x, final int y, final int z) { + return this.getWorld().getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z); + } + + public Block getRelativeBlock(final World world, final int x, final int y, final int z) { + return world.getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z); + } + + public List getChunks() { + final World world = this.getWorld(); + final int x1 = this.x1 & 0xFFFFFFF0; + final int x2 = this.x2 & 0xFFFFFFF0; + final int z1 = this.z1 & 0xFFFFFFF0; + final int z2 = this.z2 & 0xFFFFFFF0; + final List result = new ArrayList(x2 - x1 + 16 + (z2 - z1) * 16); + for (int x3 = x1; x3 <= x2; x3 += 16) { + for (int z3 = z1; z3 <= z2; z3 += 16) { + result.add(world.getChunkAt(x3 >> 4, z3 >> 4)); + } + } + return result; + } + + @Override + public Iterator iterator() { + return new CuboidBlockIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2); + } + + public Iterator locationIterator() { + return new CuboidLocationIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2); + } + + @Override + public Cuboid clone() { + try { + return (Cuboid) super.clone(); + } catch (CloneNotSupportedException ex) { + throw new RuntimeException("This could never happen", ex); + } + } + + @Override + public String toString() { + return "Cuboid: " + this.worldName + ',' + this.x1 + ',' + this.y1 + ',' + this.z1 + "=>" + this.x2 + ',' + + this.y2 + ',' + this.z2; + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.java b/src/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.java new file mode 100644 index 0000000..613edec --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.java @@ -0,0 +1,56 @@ +package LorexMC.us.utils.other.cuboid; + +import java.util.*; +import org.bukkit.block.*; +import org.bukkit.*; + +public class CuboidBlockIterator implements Iterator { + private final World world; + private final int baseX; + private final int baseY; + private final int baseZ; + private final int sizeX; + private final int sizeY; + private final int sizeZ; + private int x; + private int y; + private int z; + + public CuboidBlockIterator(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + this.world = world; + this.baseX = x1; + this.baseY = y1; + this.baseZ = z1; + this.sizeX = Math.abs(x2 - x1) + 1; + this.sizeY = Math.abs(y2 - y1) + 1; + this.sizeZ = Math.abs(z2 - z1) + 1; + final boolean x3 = false; + this.z = (x3 ? 1 : 0); + this.y = (x3 ? 1 : 0); + this.x = (x3 ? 1 : 0); + } + + @Override + public boolean hasNext() { + return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ; + } + + @Override + public Block next() { + final Block block = this.world.getBlockAt(this.baseX + this.x, this.baseY + this.y, this.baseZ + this.z); + if (++this.x >= this.sizeX) { + this.x = 0; + if (++this.y >= this.sizeY) { + this.y = 0; + ++this.z; + } + } + return block; + } + + @Override + public void remove() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CuboidDirection.java b/src/LorexMC/us/utils/other/cuboid/CuboidDirection.java new file mode 100644 index 0000000..3e6d234 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CuboidDirection.java @@ -0,0 +1,68 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.block.*; + +public enum CuboidDirection { + NORTH, EAST, SOUTH, WEST, UP, DOWN, HORIZONTAL, VERTICAL, BOTH, UNKNOWN; + + public CuboidDirection opposite() { + switch (this) { + case NORTH: { + return CuboidDirection.SOUTH; + } + case EAST: { + return CuboidDirection.WEST; + } + case SOUTH: { + return CuboidDirection.NORTH; + } + case WEST: { + return CuboidDirection.EAST; + } + case HORIZONTAL: { + return CuboidDirection.VERTICAL; + } + case VERTICAL: { + return CuboidDirection.HORIZONTAL; + } + case UP: { + return CuboidDirection.DOWN; + } + case DOWN: { + return CuboidDirection.UP; + } + case BOTH: { + return CuboidDirection.BOTH; + } + default: { + return CuboidDirection.UNKNOWN; + } + } + } + + public BlockFace toBukkitDirection() { + switch (this) { + case NORTH: { + return BlockFace.NORTH; + } + case EAST: { + return BlockFace.EAST; + } + case SOUTH: { + return BlockFace.SOUTH; + } + case WEST: { + return BlockFace.WEST; + } + case UP: { + return BlockFace.UP; + } + case DOWN: { + return BlockFace.DOWN; + } + default: { + return null; + } + } + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.java b/src/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.java new file mode 100644 index 0000000..d838803 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.java @@ -0,0 +1,56 @@ +package LorexMC.us.utils.other.cuboid; + +import java.util.*; +import org.bukkit.*; + +public class CuboidLocationIterator implements Iterator { + private final World world; + private final int baseX; + private final int baseY; + private final int baseZ; + private final int sizeX; + private final int sizeY; + private final int sizeZ; + private int x; + private int y; + private int z; + + public CuboidLocationIterator(final World world, final int x1, final int y1, final int z1, final int x2, + final int y2, final int z2) { + this.world = world; + this.baseX = x1; + this.baseY = y1; + this.baseZ = z1; + this.sizeX = Math.abs(x2 - x1) + 1; + this.sizeY = Math.abs(y2 - y1) + 1; + this.sizeZ = Math.abs(z2 - z1) + 1; + final boolean x3 = false; + this.z = (x3 ? 1 : 0); + this.y = (x3 ? 1 : 0); + this.x = (x3 ? 1 : 0); + } + + @Override + public boolean hasNext() { + return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ; + } + + @Override + public Location next() { + final Location location = new Location(this.world, this.baseX + this.x, this.baseY + this.y, + this.baseZ + this.z); + if (++this.x >= this.sizeX) { + this.x = 0; + if (++this.y >= this.sizeY) { + this.y = 0; + ++this.z; + } + } + return location; + } + + @Override + public void remove() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/NamedCuboid.java b/src/LorexMC/us/utils/other/cuboid/NamedCuboid.java new file mode 100644 index 0000000..e1e892f --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/NamedCuboid.java @@ -0,0 +1,57 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.*; + +import java.util.*; + +public class NamedCuboid extends Cuboid { + protected String name; + + public NamedCuboid(final Cuboid other) { + super(other.getWorld(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2); + } + + public NamedCuboid(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + super(world, x1, y1, z1, x2, y2, z2); + } + + public NamedCuboid(final Location location) { + super(location, location); + } + + public NamedCuboid(final Location first, final Location second) { + super(first, second); + } + + public NamedCuboid(final Map map) { + super(map); + this.name = (String) map.get("name"); + } + + @Override + public Map serialize() { + final Map map = super.serialize(); + map.put("name", this.name); + return map; + } + + public String getName() { + return this.name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public NamedCuboid clone() { + return (NamedCuboid) super.clone(); + } + + @Override + public String toString() { + return "NamedCuboid: " + this.worldName + ',' + this.x1 + ',' + this.y1 + ',' + this.z1 + "=>" + this.x2 + ',' + + this.y2 + ',' + this.z2 + ':' + this.name; + } +} diff --git a/src/LorexMC/us/utils/other/imagemessage/ImageChar.java b/src/LorexMC/us/utils/other/imagemessage/ImageChar.java new file mode 100644 index 0000000..0eeb7c5 --- /dev/null +++ b/src/LorexMC/us/utils/other/imagemessage/ImageChar.java @@ -0,0 +1,15 @@ +package LorexMC.us.utils.other.imagemessage; + +public enum ImageChar { + BLOCK('\u2588'), DARK_SHADE('\u2593'), MEDIUM_SHADE('\u2592'), LIGHT_SHADE('\u2591'); + + private final char character; + + private ImageChar(final char character) { + this.character = character; + } + + public char getChar() { + return this.character; + } +} diff --git a/src/LorexMC/us/utils/other/imagemessage/ImageMessage.java b/src/LorexMC/us/utils/other/imagemessage/ImageMessage.java new file mode 100644 index 0000000..02c7f38 --- /dev/null +++ b/src/LorexMC/us/utils/other/imagemessage/ImageMessage.java @@ -0,0 +1,182 @@ +package LorexMC.us.utils.other.imagemessage; + +import java.awt.Color; + +import com.google.common.base.*; + +import org.bukkit.*; + +import java.net.*; + +import javax.imageio.*; + +import java.io.*; +import java.awt.geom.*; +import java.awt.image.*; + +import org.bukkit.craftbukkit.libs.joptsimple.internal.Strings; + +import java.util.*; + +import org.bukkit.entity.*; + +public final class ImageMessage { + private static final char TRANSPARENT_CHAR = ' '; + private final String[] lines; + private static final Color[] colors; + + private ImageMessage(final String... lines) throws IllegalArgumentException { + Preconditions.checkNotNull((Object) lines, (Object) "Lines cannot be null"); + this.lines = lines; + } + + private ImageMessage(final BufferedImage image, final int height, final char imageCharacter) + throws IllegalArgumentException { + this(toImageMessage(toColourArray(image, height), imageCharacter)); + } + + public static ImageMessage newInstance(final BufferedImage image, final int height, final char imageCharacter) + throws IllegalArgumentException { + Preconditions.checkNotNull((Object) image, (Object) "Image cannot be null"); + Preconditions.checkArgument(height >= 0, "Height must be positive"); + return new ImageMessage(image, height, imageCharacter); + } + + public static ImageMessage newInstance(final ChatColor[][] chatColors, final char imageCharacter) { + return new ImageMessage(toImageMessage(chatColors, imageCharacter)); + } + + public static ImageMessage newInstance(final String url, final int height, final char imageCharacter) + throws IllegalArgumentException { + Preconditions.checkNotNull((Object) url, (Object) "Image URL cannot be null"); + Preconditions.checkArgument(height >= 0, "Height must be positive"); + try { + return newInstance(ImageIO.read(new URL(url)), height, imageCharacter); + } catch (IOException ex) { + throw new IllegalArgumentException(ex); + } + } + + public static ImageMessage newInstance(final String fileName, final File folder, final int height, + final char imageCharacter) throws IllegalArgumentException { + Preconditions.checkNotNull((Object) fileName, (Object) "File name cannot be null"); + Preconditions.checkNotNull((Object) folder, (Object) "Folder cannot be null"); + try { + return newInstance(ImageIO.read(new File(folder, fileName)), height, imageCharacter); + } catch (IOException ex) { + throw new IllegalArgumentException(ex); + } + } + + public ImageMessage appendText(final String... text) { + for (int i = 0; i < Math.min(text.length, this.lines.length); ++i) { + final StringBuilder sb = new StringBuilder(); + final String[] lines = this.lines; + final int n = i; + lines[n] = sb.append(lines[n]).append(' ').append(text[i]).toString(); + } + return this; + } + + public ImageMessage appendCenteredText(final String... text) { + for (int i = 0; i < Math.min(text.length, this.lines.length); ++i) { + final String line = this.lines[i]; + this.lines[i] = line + this.center(text[i], 65 - line.length()); + } + return this; + } + + private static ChatColor[][] toColourArray(final BufferedImage image, final int height) { + final double ratio = image.getHeight() / image.getWidth(); + final BufferedImage resizedImage = resizeImage(image, (int) (height / ratio), height); + final ChatColor[][] chatImage = new ChatColor[resizedImage.getWidth()][resizedImage.getHeight()]; + for (int x = 0; x < resizedImage.getWidth(); ++x) { + for (int y = 0; y < resizedImage.getHeight(); ++y) { + final ChatColor closest = getClosestChatColor(new Color(resizedImage.getRGB(x, y), true)); + chatImage[x][y] = closest; + } + } + return chatImage; + } + + private static String[] toImageMessage(final ChatColor[][] colors, final char imageCharacter) { + final String[] results = new String[colors[0].length]; + for (int i = 0; i < colors[0].length; ++i) { + final StringBuilder line = new StringBuilder(); + for (final ChatColor[] color : colors) { + final ChatColor current = color[i]; + line.append((current != null) ? (current.toString() + imageCharacter) : ImageMessage.TRANSPARENT_CHAR); + } + results[i] = line.toString() + ChatColor.RESET; + } + return results; + } + + private static BufferedImage resizeImage(final BufferedImage image, final int width, final int height) { + final AffineTransform transform = new AffineTransform(); + transform.scale(width / image.getWidth(), height / image.getHeight()); + return new AffineTransformOp(transform, 1).filter(image, null); + } + + private static double getDistance(final Color c1, final Color c2) { + final int red = c1.getRed() - c2.getRed(); + final int green = c1.getGreen() - c2.getGreen(); + final int blue = c1.getBlue() - c2.getBlue(); + final double redMean = (c1.getRed() + c2.getRed()) / 2.0; + final double weightRed = 2.0 + redMean / 256.0; + final double weightGreen = 4.0; + final double weightBlue = 2.0 + (255.0 - redMean) / 256.0; + return weightRed * red * red + weightGreen * green * green + weightBlue * blue * blue; + } + + private static boolean areIdentical(final Color c1, final Color c2) { + return Math.abs(c1.getRed() - c2.getRed()) <= 5 && Math.abs(c1.getGreen() - c2.getGreen()) <= 5 + && Math.abs(c1.getBlue() - c2.getBlue()) <= 5; + } + + private static ChatColor getClosestChatColor(final Color color) { + if (color.getAlpha() < 128) { + return null; + } + for (int i = 0; i < ImageMessage.colors.length; ++i) { + if (areIdentical(ImageMessage.colors[i], color)) { + return ChatColor.values()[i]; + } + } + int index = 0; + double best = -1.0; + for (int j = 0; j < ImageMessage.colors.length; ++j) { + final double distance = getDistance(color, ImageMessage.colors[j]); + if (distance < best || best == -1.0) { + best = distance; + index = j; + } + } + return ChatColor.values()[index]; + } + + private String center(final String string, final int length) { + if (string.length() > length) { + return string.substring(0, length); + } + if (string.length() == length) { + return string; + } + return Strings.repeat(' ', (length - string.length()) / 2) + string; + } + + public String[] getLines() { + return Arrays.copyOf(this.lines, this.lines.length); + } + + public void sendToPlayer(final Player player) { + player.sendMessage(this.lines); + } + + static { + colors = new Color[] { new Color(0, 0, 0), new Color(0, 0, 170), new Color(0, 170, 0), new Color(0, 170, 170), + new Color(170, 0, 0), new Color(170, 0, 170), new Color(255, 170, 0), new Color(170, 170, 170), + new Color(85, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85), new Color(85, 255, 255), + new Color(255, 85, 85), new Color(255, 85, 255), new Color(255, 255, 85), new Color(255, 255, 255) }; + } +} diff --git a/src/LorexMC/us/utils/other/itemdb/ItemData.java b/src/LorexMC/us/utils/other/itemdb/ItemData.java new file mode 100644 index 0000000..026f1f8 --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/ItemData.java @@ -0,0 +1,106 @@ +package LorexMC.us.utils.other.itemdb; + +import org.bukkit.configuration.serialization.*; +import org.bukkit.*; +import org.bukkit.material.*; + +import LorexMC.us.utils.internal.com.bruce.base.*; + +import org.bukkit.inventory.*; +import java.util.*; + +public class ItemData implements ConfigurationSerializable { + private final Material material; + private final short itemData; + + public ItemData(final MaterialData data) { + this(data.getItemType(), data.getData()); + } + + public ItemData(final ItemStack stack) { + this(stack.getType(), stack.getData().getData()); + } + + public ItemData(final Material material, final short itemData) { + this.material = material; + this.itemData = itemData; + } + + public ItemData(final Map map) { + Object object = map.get("itemType"); + if (!(object instanceof String)) { + throw new AssertionError("Incorrectly configurised"); + } + this.material = Material.getMaterial((String) object); + if ((object = map.get("itemData")) instanceof Short) { + this.itemData = (short) object; + return; + } + throw new AssertionError("Incorrectly configurised"); + } + + @Override + public Map serialize() { + final Map map = new LinkedHashMap(); + map.put("itemType", this.material.name()); + map.put("itemData", this.itemData); + return map; + } + + public Material getMaterial() { + return this.material; + } + + @Deprecated + public short getItemData() { + return this.itemData; + } + + public String getItemName() { + return BasePlugin.getPlugin().getItemDb().getName(new ItemStack(this.material, 1, this.itemData)); + } + + public static ItemData fromItemName(final String string) { + final ItemStack stack = BasePlugin.getPlugin().getItemDb().getItem(string); + return new ItemData(stack.getType(), stack.getData().getData()); + } + + public static ItemData fromStringValue(final String value) { + final int firstBracketIndex = value.indexOf(40); + if (firstBracketIndex == -1) { + return null; + } + final int otherBracketIndex = value.indexOf(41); + if (otherBracketIndex == -1) { + return null; + } + final String itemName = value.substring(0, firstBracketIndex); + final String itemData = value.substring(firstBracketIndex + 1, otherBracketIndex); + final Material material = Material.getMaterial(itemName); + return new ItemData(material, Short.parseShort(itemData)); + } + + @Override + public String toString() { + return String.valueOf(this.material.name()) + "(" + String.valueOf(this.itemData) + ")"; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || this.getClass() != o.getClass()) { + return false; + } + final ItemData itemData1 = (ItemData) o; + return this.itemData == itemData1.itemData && this.material == itemData1.material; + } + + @Override + public int hashCode() { + int result = (this.material != null) ? this.material.hashCode() : 0; + result = 31 * result + this.itemData; + return result; + } +} diff --git a/src/LorexMC/us/utils/other/itemdb/ItemDb.java b/src/LorexMC/us/utils/other/itemdb/ItemDb.java new file mode 100644 index 0000000..e39a89c --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/ItemDb.java @@ -0,0 +1,26 @@ +package LorexMC.us.utils.other.itemdb; + +import org.bukkit.inventory.*; +import org.bukkit.entity.*; +import java.util.*; + +public interface ItemDb { + void reloadItemDatabase(); + + ItemStack getPotion(final String p0); + + ItemStack getPotion(final String p0, final int p1); + + ItemStack getItem(final String p0); + + ItemStack getItem(final String p0, final int p1); + + String getName(final ItemStack p0); + + @Deprecated + String getPrimaryName(final ItemStack p0); + + String getNames(final ItemStack p0); + + List getMatching(final Player p0, final String[] p1); +} diff --git a/src/LorexMC/us/utils/other/itemdb/ManagedFile.java b/src/LorexMC/us/utils/other/itemdb/ManagedFile.java new file mode 100644 index 0000000..e8f5f53 --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/ManagedFile.java @@ -0,0 +1,76 @@ +package LorexMC.us.utils.other.itemdb; + +import org.bukkit.plugin.java.*; + +import LorexMC.us.utils.internal.com.bruce.base.*; + +import java.util.logging.*; +import java.nio.charset.*; +import java.math.*; +import java.security.*; +import java.nio.file.*; +import java.util.*; +import java.io.*; + +public class ManagedFile { + private static final int BUFFER_SIZE = 8192; + private final transient File file; + + public ManagedFile(final String filename, final JavaPlugin plugin) { + this.file = new File(plugin.getDataFolder(), filename); + if (!this.file.exists()) { + try { + copyResourceAscii('/' + filename, this.file); + } catch (IOException ex) { + plugin.getLogger().log(Level.SEVERE, "items.csv has not been loaded", ex); + } + } + } + + public File getFile() { + return this.file; + } + + public static void copyResourceAscii(final String resourceName, final File file) throws IOException { + try (final InputStreamReader reader = new InputStreamReader(ManagedFile.class.getResourceAsStream(resourceName), + StandardCharsets.UTF_8)) { + final MessageDigest digest = getDigest(); + try (final DigestOutputStream digestStream = new DigestOutputStream(new FileOutputStream(file), digest); + final OutputStreamWriter writer = new OutputStreamWriter(digestStream, StandardCharsets.UTF_8)) { + final char[] buffer = new char[8192]; + int length; + while ((length = reader.read(buffer)) >= 0) { + writer.write(buffer, 0, length); + } + writer.write("\n"); + writer.flush(); + digestStream.on(false); + digestStream.write(35); + digestStream.write(new BigInteger(1, digest.digest()).toString(16).getBytes(StandardCharsets.UTF_8)); + } + } + } + + public static MessageDigest getDigest() throws IOException { + try { + return MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException ex) { + throw new IOException(ex); + } + } + + public List getLines() { + try (final BufferedReader reader = Files.newBufferedReader(Paths.get(this.file.getPath(), new String[0]), + StandardCharsets.UTF_8)) { + final List lines = new ArrayList(); + String line; + while ((line = reader.readLine()) != null) { + lines.add(line); + } + return lines; + } catch (IOException ex) { + BasePlugin.getPlugin().getJavaPlugin().getLogger().log(Level.SEVERE, ex.getMessage(), ex); + return Collections.emptyList(); + } + } +} diff --git a/src/LorexMC/us/utils/other/itemdb/SimpleItemDb.java b/src/LorexMC/us/utils/other/itemdb/SimpleItemDb.java new file mode 100644 index 0000000..84d4066 --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/SimpleItemDb.java @@ -0,0 +1,317 @@ +package LorexMC.us.utils.other.itemdb; + +import gnu.trove.map.*; +import org.bukkit.plugin.java.*; + +import com.google.common.collect.*; + +import LorexMC.us.utils.JavaUtils; +import gnu.trove.map.hash.*; + +import org.bukkit.potion.*; +import org.bukkit.*; +import java.util.regex.*; +import org.bukkit.entity.*; +import org.bukkit.inventory.*; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; +import java.util.*; +import org.apache.commons.lang3.*; + +public class SimpleItemDb implements ItemDb { + private static final Comparator STRING_LENGTH_COMPARATOR; + private final TObjectIntMap items; + private final TreeMultimap names; + private final Map primaryName; + private final TObjectShortMap durabilities; + private final ManagedFile file; + private final Pattern splitPattern; + private static final Pattern PARTS_PATTERN; + + public SimpleItemDb(final JavaPlugin plugin) { + this.items = new TObjectIntHashMap(); + this.names = TreeMultimap.create((Comparator) Ordering.arbitrary(), + (Comparator) SimpleItemDb.STRING_LENGTH_COMPARATOR); + this.primaryName = new HashMap(); + this.durabilities = new TObjectShortHashMap(); + this.splitPattern = Pattern.compile("((.*)[:+',;.](\\d+))"); + this.file = new ManagedFile("items.csv", plugin); + this.reloadItemDatabase(); + } + + @Override + public void reloadItemDatabase() { + if (this.file.getFile() == null) { + return; + } + final List lines = this.file.getLines(); + if (lines.isEmpty()) { + return; + } + this.durabilities.clear(); + this.items.clear(); + this.names.clear(); + this.primaryName.clear(); + for (String line : lines) { + line = line.trim().toLowerCase(Locale.ENGLISH); + if (line.length() > 0 && line.charAt(0) == '#') { + continue; + } + final String[] parts = SimpleItemDb.PARTS_PATTERN.split(line); + if (parts.length < 2) { + continue; + } + Material material; + try { + final int numeric = Integer.parseInt(parts[1]); + material = Material.getMaterial(numeric); + } catch (IllegalArgumentException ex) { + material = Material.getMaterial(parts[1]); + } + final short data = (parts.length > 2 && !parts[2].equals("0")) ? Short.parseShort(parts[2]) : 0; + final String itemName = parts[0].toLowerCase(Locale.ENGLISH); + this.durabilities.put(itemName, data); + this.items.put(itemName, material.getId()); + final ItemData itemData = new ItemData(material, data); + if (this.names.containsKey(itemData)) { + this.names.get(itemData).add(itemName); + } else { + this.names.put(itemData, itemName); + this.primaryName.put(itemData, itemName); + } + } + } + + @Override + public ItemStack getPotion(final String id) { + return this.getPotion(id, 1); + } + + @Override + public ItemStack getPotion(String id, final int quantity) { + int length = id.length(); + if (length <= 1) { + return null; + } + boolean splash = false; + if (length > 1 && id.endsWith("s")) { + id = id.substring(0, --length); + splash = true; + if (length <= 1) { + return null; + } + } + boolean extended = false; + if (id.endsWith("e")) { + id = id.substring(0, --length); + extended = true; + if (length <= 1) { + return null; + } + } + final Integer level = JavaUtils.tryParseInt(id.substring(length - 1, length)); + id = id.substring(0, --length); + final String lowerCase = id.toLowerCase(Locale.ENGLISH); + PotionType type = null; + switch (lowerCase) { + case "hp": { + type = PotionType.FIRE_RESISTANCE; + break; + } + case "rp": { + type = PotionType.REGEN; + break; + } + case "dp": { + type = PotionType.INSTANT_DAMAGE; + break; + } + case "swp": { + type = PotionType.SPEED; + break; + } + case "slp": { + type = PotionType.SLOWNESS; + break; + } + case "strp": { + type = PotionType.STRENGTH; + break; + } + case "wp": { + type = PotionType.WEAKNESS; + break; + } + case "pp": { + type = PotionType.POISON; + break; + } + case "frp": { + type = PotionType.FIRE_RESISTANCE; + break; + } + case "invp": { + type = PotionType.INVISIBILITY; + break; + } + case "nvp": { + type = PotionType.NIGHT_VISION; + break; + } + default: { + return null; + } + } + if (level == null || level > type.getMaxLevel()) { + return null; + } + final Potion potion = new Potion(type); + potion.setLevel(level); + potion.setSplash(splash); + potion.setHasExtendedDuration(extended); + final ItemStack result = potion.toItemStack(quantity); + result.setDurability((short) (result.getDurability() + 8192)); + return result; + } + + @Override + public ItemStack getItem(final String id) { + final ItemStack result = this.getItem(id, 1); + if (result == null) { + return null; + } + result.setAmount(result.getMaxStackSize()); + return result; + } + + @Override + public ItemStack getItem(final String id, final int quantity) { + ItemStack result = this.getPotion(id, quantity); + if (result != null) { + return result; + } + int itemId = 0; + short metaData = 0; + final Matcher parts = this.splitPattern.matcher(id); + String itemName; + if (parts.matches()) { + itemName = parts.group(2); + metaData = Short.parseShort(parts.group(3)); + } else { + itemName = id; + } + Integer last; + if ((last = JavaUtils.tryParseInt(itemName)) != null) { + itemId = last; + } else if ((last = JavaUtils.tryParseInt(id)) != null) { + itemId = last; + } else { + itemName = itemName.toLowerCase(Locale.ENGLISH); + } + if (itemId < 1) { + if (this.items.containsKey(itemName)) { + itemId = this.items.get(itemName); + if (this.durabilities.containsKey(itemName) && metaData == 0) { + metaData = this.durabilities.get(itemName); + } + } else if (Material.getMaterial(itemName.toUpperCase(Locale.ENGLISH)) != null) { + final Material bMaterial = Material.getMaterial(itemName.toUpperCase(Locale.ENGLISH)); + itemId = bMaterial.getId(); + } else { + try { + final Material bMaterial = Bukkit.getUnsafe() + .getMaterialFromInternalName(itemName.toLowerCase(Locale.ENGLISH)); + itemId = bMaterial.getId(); + } catch (Exception ex) { + return null; + } + } + } + if (itemId < 1) { + return null; + } + final Material mat = Material.getMaterial(itemId); + if (mat == null) { + return null; + } + result = new ItemStack(mat); + result.setAmount(quantity); + result.setDurability(metaData); + return result; + } + + @Override + public List getMatching(final Player player, final String[] args) { + final List items = new ArrayList(); + final PlayerInventory inventory = player.getInventory(); + if (args.length < 1 || args[0].equalsIgnoreCase("hand")) { + items.add(player.getItemInHand()); + } else if (args[0].equalsIgnoreCase("inventory") || args[0].equalsIgnoreCase("invent") + || args[0].equalsIgnoreCase("all")) { + for (final ItemStack stack : inventory.getContents()) { + if (stack != null && stack.getType() != Material.AIR) { + items.add(stack); + } + } + } else if (args[0].equalsIgnoreCase("blocks")) { + for (final ItemStack stack : inventory.getContents()) { + if (stack != null && stack.getType() != Material.AIR && stack.getType().isBlock()) { + items.add(stack); + } + } + } else { + items.add(this.getItem(args[0])); + } + if (items.isEmpty() || items.get(0).getType() == Material.AIR) { + return null; + } + return items; + } + + @Override + public String getName(final ItemStack item) { + return CraftItemStack.asNMSCopy(item).getName(); + } + + @Deprecated + @Override + public String getPrimaryName(final ItemStack item) { + ItemData itemData = new ItemData(item.getType(), item.getDurability()); + String name = this.primaryName.get(itemData); + if (name == null) { + itemData = new ItemData(item.getType(), (short) 0); + name = this.primaryName.get(itemData); + if (name == null) { + return null; + } + } + return name; + } + + @Override + public String getNames(final ItemStack item) { + ItemData itemData = new ItemData(item.getType(), item.getDurability()); + Collection nameList = this.names.get(itemData); + if (nameList == null) { + itemData = new ItemData(item.getType(), (short) 0); + nameList = this.names.get(itemData); + if (nameList == null) { + return null; + } + } + List list = new ArrayList(nameList); + if (nameList.size() > 15) { + list = list.subList(0, 14); + } + return StringUtils.join(list, ", "); + } + + static { + STRING_LENGTH_COMPARATOR = new Comparator() { + @Override + public int compare(final String o1, final String o2) { + return o1.length() - o2.length(); + } + }; + PARTS_PATTERN = Pattern.compile("[^a-z0-9]"); + } +} diff --git a/src/gnu/trove/TByteCollection.java b/src/gnu/trove/TByteCollection.java new file mode 100644 index 0000000..036aba6 --- /dev/null +++ b/src/gnu/trove/TByteCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TByteIterator; +import gnu.trove.procedure.TByteProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TByteCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + byte getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an byte value + * @return true if the collection contains the specified element. + */ + boolean contains(byte entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TByteIterator value + */ + TByteIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + byte[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an byte[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + byte[] toArray(byte[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a byte value + * @return true if the collection was modified by the add operation + */ + boolean add(byte entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an byte value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(byte entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TByteCollection are present. + * + * @param collection + * a TByteCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TByteCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of byte primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(byte[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TByteCollection to the collection. + * + * @param collection + * a TByteCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TByteCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of byte primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(byte[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TByteCollection. + * + * @param collection + * a TByteCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TByteCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of byte primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(byte[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TByteCollection from the collection. + * + * @param collection + * a TByteCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TByteCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of byte primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(byte[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TByteProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TByteCollection diff --git a/src/gnu/trove/TCharCollection.java b/src/gnu/trove/TCharCollection.java new file mode 100644 index 0000000..7cfd3eb --- /dev/null +++ b/src/gnu/trove/TCharCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TCharIterator; +import gnu.trove.procedure.TCharProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TCharCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + char getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an char value + * @return true if the collection contains the specified element. + */ + boolean contains(char entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TCharIterator value + */ + TCharIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + char[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an char[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + char[] toArray(char[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a char value + * @return true if the collection was modified by the add operation + */ + boolean add(char entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an char value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(char entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TCharCollection are present. + * + * @param collection + * a TCharCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TCharCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of char primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(char[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TCharCollection to the collection. + * + * @param collection + * a TCharCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TCharCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of char primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(char[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TCharCollection. + * + * @param collection + * a TCharCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TCharCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of char primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(char[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TCharCollection from the collection. + * + * @param collection + * a TCharCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TCharCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of char primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(char[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TCharProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TCharCollection diff --git a/src/gnu/trove/TCollections.java b/src/gnu/trove/TCollections.java new file mode 100644 index 0000000..8d5cff2 --- /dev/null +++ b/src/gnu/trove/TCollections.java @@ -0,0 +1,4620 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.set.*; +import gnu.trove.list.*; +import gnu.trove.map.*; +import gnu.trove.impl.unmodifiable.*; +import gnu.trove.impl.sync.*; + +import java.util.RandomAccess; + +/** + * Trove equivalent of the {@link java.util.Collections} class. + */ +@SuppressWarnings({ "UnusedDeclaration" }) +public class TCollections { + + // Disallow creation of instances of this class + private TCollections() { + } + + /////////////////////////// + // TUnmodifiableCollections + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TDoubleCollection unmodifiableCollection(TDoubleCollection c) { + return new TUnmodifiableDoubleCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TFloatCollection unmodifiableCollection(TFloatCollection c) { + return new TUnmodifiableFloatCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TIntCollection unmodifiableCollection(TIntCollection c) { + return new TUnmodifiableIntCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TLongCollection unmodifiableCollection(TLongCollection c) { + return new TUnmodifiableLongCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TByteCollection unmodifiableCollection(TByteCollection c) { + return new TUnmodifiableByteCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TShortCollection unmodifiableCollection(TShortCollection c) { + return new TUnmodifiableShortCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TCharCollection unmodifiableCollection(TCharCollection c) { + return new TUnmodifiableCharCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TDoubleSet unmodifiableSet(TDoubleSet s) { + return new TUnmodifiableDoubleSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TFloatSet unmodifiableSet(TFloatSet s) { + return new TUnmodifiableFloatSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TIntSet unmodifiableSet(TIntSet s) { + return new TUnmodifiableIntSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TLongSet unmodifiableSet(TLongSet s) { + return new TUnmodifiableLongSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TByteSet unmodifiableSet(TByteSet s) { + return new TUnmodifiableByteSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TShortSet unmodifiableSet(TShortSet s) { + return new TUnmodifiableShortSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TCharSet unmodifiableSet(TCharSet s) { + return new TUnmodifiableCharSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TDoubleList unmodifiableList(TDoubleList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessDoubleList(list) + : new TUnmodifiableDoubleList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TFloatList unmodifiableList(TFloatList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessFloatList(list) + : new TUnmodifiableFloatList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TIntList unmodifiableList(TIntList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessIntList(list) + : new TUnmodifiableIntList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TLongList unmodifiableList(TLongList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessLongList(list) + : new TUnmodifiableLongList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TByteList unmodifiableList(TByteList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessByteList(list) + : new TUnmodifiableByteList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TShortList unmodifiableList(TShortList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessShortList(list) + : new TUnmodifiableShortList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TCharList unmodifiableList(TCharList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessCharList(list) + : new TUnmodifiableCharList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleDoubleMap unmodifiableMap(TDoubleDoubleMap m) { + return new TUnmodifiableDoubleDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleFloatMap unmodifiableMap(TDoubleFloatMap m) { + return new TUnmodifiableDoubleFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleIntMap unmodifiableMap(TDoubleIntMap m) { + return new TUnmodifiableDoubleIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleLongMap unmodifiableMap(TDoubleLongMap m) { + return new TUnmodifiableDoubleLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleByteMap unmodifiableMap(TDoubleByteMap m) { + return new TUnmodifiableDoubleByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleShortMap unmodifiableMap(TDoubleShortMap m) { + return new TUnmodifiableDoubleShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleCharMap unmodifiableMap(TDoubleCharMap m) { + return new TUnmodifiableDoubleCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatDoubleMap unmodifiableMap(TFloatDoubleMap m) { + return new TUnmodifiableFloatDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatFloatMap unmodifiableMap(TFloatFloatMap m) { + return new TUnmodifiableFloatFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatIntMap unmodifiableMap(TFloatIntMap m) { + return new TUnmodifiableFloatIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatLongMap unmodifiableMap(TFloatLongMap m) { + return new TUnmodifiableFloatLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatByteMap unmodifiableMap(TFloatByteMap m) { + return new TUnmodifiableFloatByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatShortMap unmodifiableMap(TFloatShortMap m) { + return new TUnmodifiableFloatShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatCharMap unmodifiableMap(TFloatCharMap m) { + return new TUnmodifiableFloatCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntDoubleMap unmodifiableMap(TIntDoubleMap m) { + return new TUnmodifiableIntDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntFloatMap unmodifiableMap(TIntFloatMap m) { + return new TUnmodifiableIntFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntIntMap unmodifiableMap(TIntIntMap m) { + return new TUnmodifiableIntIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntLongMap unmodifiableMap(TIntLongMap m) { + return new TUnmodifiableIntLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntByteMap unmodifiableMap(TIntByteMap m) { + return new TUnmodifiableIntByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntShortMap unmodifiableMap(TIntShortMap m) { + return new TUnmodifiableIntShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntCharMap unmodifiableMap(TIntCharMap m) { + return new TUnmodifiableIntCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongDoubleMap unmodifiableMap(TLongDoubleMap m) { + return new TUnmodifiableLongDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongFloatMap unmodifiableMap(TLongFloatMap m) { + return new TUnmodifiableLongFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongIntMap unmodifiableMap(TLongIntMap m) { + return new TUnmodifiableLongIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongLongMap unmodifiableMap(TLongLongMap m) { + return new TUnmodifiableLongLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongByteMap unmodifiableMap(TLongByteMap m) { + return new TUnmodifiableLongByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongShortMap unmodifiableMap(TLongShortMap m) { + return new TUnmodifiableLongShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongCharMap unmodifiableMap(TLongCharMap m) { + return new TUnmodifiableLongCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteDoubleMap unmodifiableMap(TByteDoubleMap m) { + return new TUnmodifiableByteDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteFloatMap unmodifiableMap(TByteFloatMap m) { + return new TUnmodifiableByteFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteIntMap unmodifiableMap(TByteIntMap m) { + return new TUnmodifiableByteIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteLongMap unmodifiableMap(TByteLongMap m) { + return new TUnmodifiableByteLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteByteMap unmodifiableMap(TByteByteMap m) { + return new TUnmodifiableByteByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteShortMap unmodifiableMap(TByteShortMap m) { + return new TUnmodifiableByteShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteCharMap unmodifiableMap(TByteCharMap m) { + return new TUnmodifiableByteCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortDoubleMap unmodifiableMap(TShortDoubleMap m) { + return new TUnmodifiableShortDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortFloatMap unmodifiableMap(TShortFloatMap m) { + return new TUnmodifiableShortFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortIntMap unmodifiableMap(TShortIntMap m) { + return new TUnmodifiableShortIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortLongMap unmodifiableMap(TShortLongMap m) { + return new TUnmodifiableShortLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortByteMap unmodifiableMap(TShortByteMap m) { + return new TUnmodifiableShortByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortShortMap unmodifiableMap(TShortShortMap m) { + return new TUnmodifiableShortShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortCharMap unmodifiableMap(TShortCharMap m) { + return new TUnmodifiableShortCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharDoubleMap unmodifiableMap(TCharDoubleMap m) { + return new TUnmodifiableCharDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharFloatMap unmodifiableMap(TCharFloatMap m) { + return new TUnmodifiableCharFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharIntMap unmodifiableMap(TCharIntMap m) { + return new TUnmodifiableCharIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharLongMap unmodifiableMap(TCharLongMap m) { + return new TUnmodifiableCharLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharByteMap unmodifiableMap(TCharByteMap m) { + return new TUnmodifiableCharByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharShortMap unmodifiableMap(TCharShortMap m) { + return new TUnmodifiableCharShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharCharMap unmodifiableMap(TCharCharMap m) { + return new TUnmodifiableCharCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleObjectMap unmodifiableMap(TDoubleObjectMap m) { + return new TUnmodifiableDoubleObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatObjectMap unmodifiableMap(TFloatObjectMap m) { + return new TUnmodifiableFloatObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntObjectMap unmodifiableMap(TIntObjectMap m) { + return new TUnmodifiableIntObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongObjectMap unmodifiableMap(TLongObjectMap m) { + return new TUnmodifiableLongObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteObjectMap unmodifiableMap(TByteObjectMap m) { + return new TUnmodifiableByteObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortObjectMap unmodifiableMap(TShortObjectMap m) { + return new TUnmodifiableShortObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharObjectMap unmodifiableMap(TCharObjectMap m) { + return new TUnmodifiableCharObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectDoubleMap unmodifiableMap(TObjectDoubleMap m) { + return new TUnmodifiableObjectDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectFloatMap unmodifiableMap(TObjectFloatMap m) { + return new TUnmodifiableObjectFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectIntMap unmodifiableMap(TObjectIntMap m) { + return new TUnmodifiableObjectIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectLongMap unmodifiableMap(TObjectLongMap m) { + return new TUnmodifiableObjectLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectByteMap unmodifiableMap(TObjectByteMap m) { + return new TUnmodifiableObjectByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectShortMap unmodifiableMap(TObjectShortMap m) { + return new TUnmodifiableObjectShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectCharMap unmodifiableMap(TObjectCharMap m) { + return new TUnmodifiableObjectCharMap(m); + } + + /////////////////////////// + // TSynchronizedCollections + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TDoubleCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TDoubleIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TDoubleCollection synchronizedCollection(TDoubleCollection c) { + return new TSynchronizedDoubleCollection(c); + } + + static TDoubleCollection synchronizedCollection(TDoubleCollection c, Object mutex) { + return new TSynchronizedDoubleCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TFloatCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TFloatIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TFloatCollection synchronizedCollection(TFloatCollection c) { + return new TSynchronizedFloatCollection(c); + } + + static TFloatCollection synchronizedCollection(TFloatCollection c, Object mutex) { + return new TSynchronizedFloatCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TIntCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TIntIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TIntCollection synchronizedCollection(TIntCollection c) { + return new TSynchronizedIntCollection(c); + } + + static TIntCollection synchronizedCollection(TIntCollection c, Object mutex) { + return new TSynchronizedIntCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TLongCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TLongIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TLongCollection synchronizedCollection(TLongCollection c) { + return new TSynchronizedLongCollection(c); + } + + static TLongCollection synchronizedCollection(TLongCollection c, Object mutex) { + return new TSynchronizedLongCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TByteCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TByteIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TByteCollection synchronizedCollection(TByteCollection c) { + return new TSynchronizedByteCollection(c); + } + + static TByteCollection synchronizedCollection(TByteCollection c, Object mutex) { + return new TSynchronizedByteCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TShortCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TShortIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TShortCollection synchronizedCollection(TShortCollection c) { + return new TSynchronizedShortCollection(c); + } + + static TShortCollection synchronizedCollection(TShortCollection c, Object mutex) { + return new TSynchronizedShortCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TCharCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TCharIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TCharCollection synchronizedCollection(TCharCollection c) { + return new TSynchronizedCharCollection(c); + } + + static TCharCollection synchronizedCollection(TCharCollection c, Object mutex) { + return new TSynchronizedCharCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TDoubleSet s = TCollections.synchronizedSet( new TDoubleHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TDoubleIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TDoubleSet synchronizedSet(TDoubleSet s) { + return new TSynchronizedDoubleSet(s); + } + + static TDoubleSet synchronizedSet(TDoubleSet s, Object mutex) { + return new TSynchronizedDoubleSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TFloatSet s = TCollections.synchronizedSet( new TFloatHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TFloatIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TFloatSet synchronizedSet(TFloatSet s) { + return new TSynchronizedFloatSet(s); + } + + static TFloatSet synchronizedSet(TFloatSet s, Object mutex) { + return new TSynchronizedFloatSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TIntSet s = TCollections.synchronizedSet( new TIntHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TIntIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TIntSet synchronizedSet(TIntSet s) { + return new TSynchronizedIntSet(s); + } + + static TIntSet synchronizedSet(TIntSet s, Object mutex) { + return new TSynchronizedIntSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TLongSet s = TCollections.synchronizedSet( new TLongHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TLongIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TLongSet synchronizedSet(TLongSet s) { + return new TSynchronizedLongSet(s); + } + + static TLongSet synchronizedSet(TLongSet s, Object mutex) { + return new TSynchronizedLongSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TByteSet s = TCollections.synchronizedSet( new TByteHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TByteIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TByteSet synchronizedSet(TByteSet s) { + return new TSynchronizedByteSet(s); + } + + static TByteSet synchronizedSet(TByteSet s, Object mutex) { + return new TSynchronizedByteSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TShortSet s = TCollections.synchronizedSet( new TShortHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TShortIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TShortSet synchronizedSet(TShortSet s) { + return new TSynchronizedShortSet(s); + } + + static TShortSet synchronizedSet(TShortSet s, Object mutex) { + return new TSynchronizedShortSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TCharSet s = TCollections.synchronizedSet( new TCharHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TCharIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TCharSet synchronizedSet(TCharSet s) { + return new TSynchronizedCharSet(s); + } + + static TCharSet synchronizedSet(TCharSet s, Object mutex) { + return new TSynchronizedCharSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TDoubleList list = TCollections.synchronizedList( new TDoubleArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TDoubleIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TDoubleList synchronizedList(TDoubleList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessDoubleList(list) + : new TSynchronizedDoubleList(list)); + } + + static TDoubleList synchronizedList(TDoubleList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessDoubleList(list, mutex) + : new TSynchronizedDoubleList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TFloatList list = TCollections.synchronizedList( new TFloatArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TFloatIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TFloatList synchronizedList(TFloatList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessFloatList(list) + : new TSynchronizedFloatList(list)); + } + + static TFloatList synchronizedList(TFloatList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessFloatList(list, mutex) + : new TSynchronizedFloatList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TIntList list = TCollections.synchronizedList( new TIntArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TIntIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TIntList synchronizedList(TIntList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessIntList(list) + : new TSynchronizedIntList(list)); + } + + static TIntList synchronizedList(TIntList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessIntList(list, mutex) + : new TSynchronizedIntList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TLongList list = TCollections.synchronizedList( new TLongArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TLongIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TLongList synchronizedList(TLongList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessLongList(list) + : new TSynchronizedLongList(list)); + } + + static TLongList synchronizedList(TLongList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessLongList(list, mutex) + : new TSynchronizedLongList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TByteList list = TCollections.synchronizedList( new TByteArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TByteIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TByteList synchronizedList(TByteList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessByteList(list) + : new TSynchronizedByteList(list)); + } + + static TByteList synchronizedList(TByteList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessByteList(list, mutex) + : new TSynchronizedByteList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TShortList list = TCollections.synchronizedList( new TShortArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TShortIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TShortList synchronizedList(TShortList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessShortList(list) + : new TSynchronizedShortList(list)); + } + + static TShortList synchronizedList(TShortList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessShortList(list, mutex) + : new TSynchronizedShortList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TCharList list = TCollections.synchronizedList( new TCharArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TCharIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TCharList synchronizedList(TCharList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessCharList(list) + : new TSynchronizedCharList(list)); + } + + static TCharList synchronizedList(TCharList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessCharList(list, mutex) + : new TSynchronizedCharList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleDoubleMap m = TCollections.synchronizedMap( new TDoubleDoubleHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleDoubleMap synchronizedMap(TDoubleDoubleMap m) { + return new TSynchronizedDoubleDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleFloatMap m = TCollections.synchronizedMap( new TDoubleFloatHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleFloatMap synchronizedMap(TDoubleFloatMap m) { + return new TSynchronizedDoubleFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleIntMap m = TCollections.synchronizedMap( new TDoubleIntHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleIntMap synchronizedMap(TDoubleIntMap m) { + return new TSynchronizedDoubleIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleLongMap m = TCollections.synchronizedMap( new TDoubleLongHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleLongMap synchronizedMap(TDoubleLongMap m) { + return new TSynchronizedDoubleLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleByteMap m = TCollections.synchronizedMap( new TDoubleByteHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleByteMap synchronizedMap(TDoubleByteMap m) { + return new TSynchronizedDoubleByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleShortMap m = TCollections.synchronizedMap( new TDoubleShortHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleShortMap synchronizedMap(TDoubleShortMap m) { + return new TSynchronizedDoubleShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleCharMap m = TCollections.synchronizedMap( new TDoubleCharHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleCharMap synchronizedMap(TDoubleCharMap m) { + return new TSynchronizedDoubleCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatDoubleMap m = TCollections.synchronizedMap( new TFloatDoubleHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatDoubleMap synchronizedMap(TFloatDoubleMap m) { + return new TSynchronizedFloatDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatFloatMap m = TCollections.synchronizedMap( new TFloatFloatHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatFloatMap synchronizedMap(TFloatFloatMap m) { + return new TSynchronizedFloatFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatIntMap m = TCollections.synchronizedMap( new TFloatIntHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatIntMap synchronizedMap(TFloatIntMap m) { + return new TSynchronizedFloatIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatLongMap m = TCollections.synchronizedMap( new TFloatLongHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatLongMap synchronizedMap(TFloatLongMap m) { + return new TSynchronizedFloatLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatByteMap m = TCollections.synchronizedMap( new TFloatByteHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatByteMap synchronizedMap(TFloatByteMap m) { + return new TSynchronizedFloatByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatShortMap m = TCollections.synchronizedMap( new TFloatShortHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatShortMap synchronizedMap(TFloatShortMap m) { + return new TSynchronizedFloatShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatCharMap m = TCollections.synchronizedMap( new TFloatCharHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatCharMap synchronizedMap(TFloatCharMap m) { + return new TSynchronizedFloatCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntDoubleMap m = TCollections.synchronizedMap( new TIntDoubleHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntDoubleMap synchronizedMap(TIntDoubleMap m) { + return new TSynchronizedIntDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntFloatMap m = TCollections.synchronizedMap( new TIntFloatHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntFloatMap synchronizedMap(TIntFloatMap m) { + return new TSynchronizedIntFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntIntMap m = TCollections.synchronizedMap( new TIntIntHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntIntMap synchronizedMap(TIntIntMap m) { + return new TSynchronizedIntIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntLongMap m = TCollections.synchronizedMap( new TIntLongHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntLongMap synchronizedMap(TIntLongMap m) { + return new TSynchronizedIntLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntByteMap m = TCollections.synchronizedMap( new TIntByteHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntByteMap synchronizedMap(TIntByteMap m) { + return new TSynchronizedIntByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntShortMap m = TCollections.synchronizedMap( new TIntShortHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntShortMap synchronizedMap(TIntShortMap m) { + return new TSynchronizedIntShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntCharMap m = TCollections.synchronizedMap( new TIntCharHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntCharMap synchronizedMap(TIntCharMap m) { + return new TSynchronizedIntCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongDoubleMap m = TCollections.synchronizedMap( new TLongDoubleHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongDoubleMap synchronizedMap(TLongDoubleMap m) { + return new TSynchronizedLongDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongFloatMap m = TCollections.synchronizedMap( new TLongFloatHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongFloatMap synchronizedMap(TLongFloatMap m) { + return new TSynchronizedLongFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongIntMap m = TCollections.synchronizedMap( new TLongIntHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongIntMap synchronizedMap(TLongIntMap m) { + return new TSynchronizedLongIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongLongMap m = TCollections.synchronizedMap( new TLongLongHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongLongMap synchronizedMap(TLongLongMap m) { + return new TSynchronizedLongLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongByteMap m = TCollections.synchronizedMap( new TLongByteHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongByteMap synchronizedMap(TLongByteMap m) { + return new TSynchronizedLongByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongShortMap m = TCollections.synchronizedMap( new TLongShortHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongShortMap synchronizedMap(TLongShortMap m) { + return new TSynchronizedLongShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongCharMap m = TCollections.synchronizedMap( new TLongCharHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongCharMap synchronizedMap(TLongCharMap m) { + return new TSynchronizedLongCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteDoubleMap m = TCollections.synchronizedMap( new TByteDoubleHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteDoubleMap synchronizedMap(TByteDoubleMap m) { + return new TSynchronizedByteDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteFloatMap m = TCollections.synchronizedMap( new TByteFloatHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteFloatMap synchronizedMap(TByteFloatMap m) { + return new TSynchronizedByteFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteIntMap m = TCollections.synchronizedMap( new TByteIntHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteIntMap synchronizedMap(TByteIntMap m) { + return new TSynchronizedByteIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteLongMap m = TCollections.synchronizedMap( new TByteLongHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteLongMap synchronizedMap(TByteLongMap m) { + return new TSynchronizedByteLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteByteMap m = TCollections.synchronizedMap( new TByteByteHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteByteMap synchronizedMap(TByteByteMap m) { + return new TSynchronizedByteByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteShortMap m = TCollections.synchronizedMap( new TByteShortHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteShortMap synchronizedMap(TByteShortMap m) { + return new TSynchronizedByteShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteCharMap m = TCollections.synchronizedMap( new TByteCharHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteCharMap synchronizedMap(TByteCharMap m) { + return new TSynchronizedByteCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortDoubleMap m = TCollections.synchronizedMap( new TShortDoubleHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortDoubleMap synchronizedMap(TShortDoubleMap m) { + return new TSynchronizedShortDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortFloatMap m = TCollections.synchronizedMap( new TShortFloatHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortFloatMap synchronizedMap(TShortFloatMap m) { + return new TSynchronizedShortFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortIntMap m = TCollections.synchronizedMap( new TShortIntHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortIntMap synchronizedMap(TShortIntMap m) { + return new TSynchronizedShortIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortLongMap m = TCollections.synchronizedMap( new TShortLongHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortLongMap synchronizedMap(TShortLongMap m) { + return new TSynchronizedShortLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortByteMap m = TCollections.synchronizedMap( new TShortByteHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortByteMap synchronizedMap(TShortByteMap m) { + return new TSynchronizedShortByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortShortMap m = TCollections.synchronizedMap( new TShortShortHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortShortMap synchronizedMap(TShortShortMap m) { + return new TSynchronizedShortShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortCharMap m = TCollections.synchronizedMap( new TShortCharHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortCharMap synchronizedMap(TShortCharMap m) { + return new TSynchronizedShortCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharDoubleMap m = TCollections.synchronizedMap( new TCharDoubleHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharDoubleMap synchronizedMap(TCharDoubleMap m) { + return new TSynchronizedCharDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharFloatMap m = TCollections.synchronizedMap( new TCharFloatHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharFloatMap synchronizedMap(TCharFloatMap m) { + return new TSynchronizedCharFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharIntMap m = TCollections.synchronizedMap( new TCharIntHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharIntMap synchronizedMap(TCharIntMap m) { + return new TSynchronizedCharIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharLongMap m = TCollections.synchronizedMap( new TCharLongHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharLongMap synchronizedMap(TCharLongMap m) { + return new TSynchronizedCharLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharByteMap m = TCollections.synchronizedMap( new TCharByteHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharByteMap synchronizedMap(TCharByteMap m) { + return new TSynchronizedCharByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharShortMap m = TCollections.synchronizedMap( new TCharShortHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharShortMap synchronizedMap(TCharShortMap m) { + return new TSynchronizedCharShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharCharMap m = TCollections.synchronizedMap( new TCharCharHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharCharMap synchronizedMap(TCharCharMap m) { + return new TSynchronizedCharCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleObjectMap m = TCollections.synchronizedMap( new TDoubleObjectHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleObjectMap synchronizedMap(TDoubleObjectMap m) { + return new TSynchronizedDoubleObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatObjectMap m = TCollections.synchronizedMap( new TFloatObjectHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatObjectMap synchronizedMap(TFloatObjectMap m) { + return new TSynchronizedFloatObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntObjectMap m = TCollections.synchronizedMap( new TIntObjectHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntObjectMap synchronizedMap(TIntObjectMap m) { + return new TSynchronizedIntObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongObjectMap m = TCollections.synchronizedMap( new TLongObjectHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongObjectMap synchronizedMap(TLongObjectMap m) { + return new TSynchronizedLongObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteObjectMap m = TCollections.synchronizedMap( new TByteObjectHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteObjectMap synchronizedMap(TByteObjectMap m) { + return new TSynchronizedByteObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortObjectMap m = TCollections.synchronizedMap( new TShortObjectHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortObjectMap synchronizedMap(TShortObjectMap m) { + return new TSynchronizedShortObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharObjectMap m = TCollections.synchronizedMap( new TCharObjectHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharObjectMap synchronizedMap(TCharObjectMap m) { + return new TSynchronizedCharObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectDoubleMap m = TCollections.synchronizedMap( new TObjectDoubleHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectDoubleMap synchronizedMap(TObjectDoubleMap m) { + return new TSynchronizedObjectDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectFloatMap m = TCollections.synchronizedMap( new TObjectFloatHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectFloatMap synchronizedMap(TObjectFloatMap m) { + return new TSynchronizedObjectFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectIntMap m = TCollections.synchronizedMap( new TObjectIntHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectIntMap synchronizedMap(TObjectIntMap m) { + return new TSynchronizedObjectIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectLongMap m = TCollections.synchronizedMap( new TObjectLongHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectLongMap synchronizedMap(TObjectLongMap m) { + return new TSynchronizedObjectLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectByteMap m = TCollections.synchronizedMap( new TObjectByteHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectByteMap synchronizedMap(TObjectByteMap m) { + return new TSynchronizedObjectByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectShortMap m = TCollections.synchronizedMap( new TObjectShortHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectShortMap synchronizedMap(TObjectShortMap m) { + return new TSynchronizedObjectShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectCharMap m = TCollections.synchronizedMap( new TObjectCharHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectCharMap synchronizedMap(TObjectCharMap m) { + return new TSynchronizedObjectCharMap(m); + } +} \ No newline at end of file diff --git a/src/gnu/trove/TDecorators.java b/src/gnu/trove/TDecorators.java new file mode 100644 index 0000000..a0bf2c0 --- /dev/null +++ b/src/gnu/trove/TDecorators.java @@ -0,0 +1,965 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +import java.util.*; + +import gnu.trove.list.*; +import gnu.trove.map.*; +import gnu.trove.set.*; +import gnu.trove.decorator.*; + +/** + * This is a static utility class that provides functions for simplifying + * creation of decorators. + * + * @author Robert D. Eden + * @author Jeff Randall + * @since Trove 2.1 + */ +public class TDecorators { + // Hide the constructor + private TDecorators() { + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleDoubleMap map) { + return new TDoubleDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleFloatMap map) { + return new TDoubleFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleIntMap map) { + return new TDoubleIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleLongMap map) { + return new TDoubleLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleByteMap map) { + return new TDoubleByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleShortMap map) { + return new TDoubleShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleCharMap map) { + return new TDoubleCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatDoubleMap map) { + return new TFloatDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatFloatMap map) { + return new TFloatFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatIntMap map) { + return new TFloatIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatLongMap map) { + return new TFloatLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatByteMap map) { + return new TFloatByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatShortMap map) { + return new TFloatShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatCharMap map) { + return new TFloatCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntDoubleMap map) { + return new TIntDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntFloatMap map) { + return new TIntFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntIntMap map) { + return new TIntIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntLongMap map) { + return new TIntLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntByteMap map) { + return new TIntByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntShortMap map) { + return new TIntShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntCharMap map) { + return new TIntCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongDoubleMap map) { + return new TLongDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongFloatMap map) { + return new TLongFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongIntMap map) { + return new TLongIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongLongMap map) { + return new TLongLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongByteMap map) { + return new TLongByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongShortMap map) { + return new TLongShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongCharMap map) { + return new TLongCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteDoubleMap map) { + return new TByteDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteFloatMap map) { + return new TByteFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteIntMap map) { + return new TByteIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteLongMap map) { + return new TByteLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteByteMap map) { + return new TByteByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteShortMap map) { + return new TByteShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteCharMap map) { + return new TByteCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortDoubleMap map) { + return new TShortDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortFloatMap map) { + return new TShortFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortIntMap map) { + return new TShortIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortLongMap map) { + return new TShortLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortByteMap map) { + return new TShortByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortShortMap map) { + return new TShortShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortCharMap map) { + return new TShortCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharDoubleMap map) { + return new TCharDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharFloatMap map) { + return new TCharFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharIntMap map) { + return new TCharIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharLongMap map) { + return new TCharLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharByteMap map) { + return new TCharByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharShortMap map) { + return new TCharShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharCharMap map) { + return new TCharCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectDoubleMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectDoubleMap map) { + return new TObjectDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectFloatMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectFloatMap map) { + return new TObjectFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectIntMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectIntMap map) { + return new TObjectIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectLongMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectLongMap map) { + return new TObjectLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectByteMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectByteMap map) { + return new TObjectByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectShortMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectShortMap map) { + return new TObjectShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectCharMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectCharMap map) { + return new TObjectCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleObjectMap map) { + return new TDoubleObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatObjectMap map) { + return new TFloatObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntObjectMap map) { + return new TIntObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongObjectMap map) { + return new TLongObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteObjectMap map) { + return new TByteObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortObjectMap map) { + return new TShortObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharObjectMap map) { + return new TCharObjectMapDecorator(map); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TDoubleSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TDoubleSet set) { + return new TDoubleSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TFloatSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TFloatSet set) { + return new TFloatSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TIntSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TIntSet set) { + return new TIntSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TLongSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TLongSet set) { + return new TLongSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TByteSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TByteSet set) { + return new TByteSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TShortSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TShortSet set) { + return new TShortSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TCharSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TCharSet set) { + return new TCharSetDecorator(set); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TDoubleList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TDoubleList list) { + return new TDoubleListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TFloatList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TFloatList list) { + return new TFloatListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TIntList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TIntList list) { + return new TIntListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TLongList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TLongList list) { + return new TLongListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TByteList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TByteList list) { + return new TByteListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TShortList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TShortList list) { + return new TShortListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TCharList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TCharList list) { + return new TCharListDecorator(list); + } +} \ No newline at end of file diff --git a/src/gnu/trove/TDoubleCollection.java b/src/gnu/trove/TDoubleCollection.java new file mode 100644 index 0000000..464a809 --- /dev/null +++ b/src/gnu/trove/TDoubleCollection.java @@ -0,0 +1,314 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.procedure.TDoubleProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TDoubleCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + double getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an double value + * @return true if the collection contains the specified element. + */ + boolean contains(double entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TDoubleIterator value + */ + TDoubleIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + double[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an double[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + double[] toArray(double[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a double value + * @return true if the collection was modified by the add operation + */ + boolean add(double entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an double value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(double entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TDoubleCollection are present. + * + * @param collection + * a TDoubleCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TDoubleCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of double primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(double[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TDoubleCollection to the collection. + * + * @param collection + * a TDoubleCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TDoubleCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of double primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(double[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TDoubleCollection. + * + * @param collection + * a TDoubleCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TDoubleCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of double primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(double[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TDoubleCollection from the + * collection. + * + * @param collection + * a TDoubleCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TDoubleCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of double primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(double[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TDoubleProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TDoubleCollection diff --git a/src/gnu/trove/TFloatCollection.java b/src/gnu/trove/TFloatCollection.java new file mode 100644 index 0000000..2df97f6 --- /dev/null +++ b/src/gnu/trove/TFloatCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.procedure.TFloatProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TFloatCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + float getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an float value + * @return true if the collection contains the specified element. + */ + boolean contains(float entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TFloatIterator value + */ + TFloatIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + float[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an float[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + float[] toArray(float[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a float value + * @return true if the collection was modified by the add operation + */ + boolean add(float entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an float value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(float entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TFloatCollection are present. + * + * @param collection + * a TFloatCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TFloatCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of float primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(float[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TFloatCollection to the collection. + * + * @param collection + * a TFloatCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TFloatCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of float primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(float[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TFloatCollection. + * + * @param collection + * a TFloatCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TFloatCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of float primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(float[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TFloatCollection from the collection. + * + * @param collection + * a TFloatCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TFloatCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of float primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(float[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TFloatProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TFloatCollection diff --git a/src/gnu/trove/TIntCollection.java b/src/gnu/trove/TIntCollection.java new file mode 100644 index 0000000..7c7330e --- /dev/null +++ b/src/gnu/trove/TIntCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TIntIterator; +import gnu.trove.procedure.TIntProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TIntCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + int getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an int value + * @return true if the collection contains the specified element. + */ + boolean contains(int entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TIntIterator value + */ + TIntIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + int[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an int[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + int[] toArray(int[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a int value + * @return true if the collection was modified by the add operation + */ + boolean add(int entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an int value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(int entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TIntCollection are present. + * + * @param collection + * a TIntCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TIntCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of int primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(int[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TIntCollection to the collection. + * + * @param collection + * a TIntCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TIntCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of int primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(int[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TIntCollection. + * + * @param collection + * a TIntCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TIntCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of int primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(int[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TIntCollection from the collection. + * + * @param collection + * a TIntCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TIntCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of int primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(int[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TIntProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TIntCollection diff --git a/src/gnu/trove/TLongCollection.java b/src/gnu/trove/TLongCollection.java new file mode 100644 index 0000000..690ec1f --- /dev/null +++ b/src/gnu/trove/TLongCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TLongIterator; +import gnu.trove.procedure.TLongProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TLongCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + long getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an long value + * @return true if the collection contains the specified element. + */ + boolean contains(long entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TLongIterator value + */ + TLongIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + long[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an long[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + long[] toArray(long[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a long value + * @return true if the collection was modified by the add operation + */ + boolean add(long entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an long value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(long entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TLongCollection are present. + * + * @param collection + * a TLongCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TLongCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of long primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(long[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TLongCollection to the collection. + * + * @param collection + * a TLongCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TLongCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of long primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(long[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TLongCollection. + * + * @param collection + * a TLongCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TLongCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of long primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(long[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TLongCollection from the collection. + * + * @param collection + * a TLongCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TLongCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of long primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(long[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TLongProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TLongCollection diff --git a/src/gnu/trove/TShortCollection.java b/src/gnu/trove/TShortCollection.java new file mode 100644 index 0000000..5737766 --- /dev/null +++ b/src/gnu/trove/TShortCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TShortIterator; +import gnu.trove.procedure.TShortProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TShortCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + short getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an short value + * @return true if the collection contains the specified element. + */ + boolean contains(short entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TShortIterator value + */ + TShortIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + short[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an short[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + short[] toArray(short[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a short value + * @return true if the collection was modified by the add operation + */ + boolean add(short entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an short value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(short entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TShortCollection are present. + * + * @param collection + * a TShortCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TShortCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of short primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(short[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TShortCollection to the collection. + * + * @param collection + * a TShortCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TShortCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of short primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(short[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TShortCollection. + * + * @param collection + * a TShortCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TShortCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of short primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(short[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TShortCollection from the collection. + * + * @param collection + * a TShortCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TShortCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of short primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(short[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TShortProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TShortCollection diff --git a/src/gnu/trove/Version.java b/src/gnu/trove/Version.java new file mode 100644 index 0000000..cfba900 --- /dev/null +++ b/src/gnu/trove/Version.java @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +/** + * Simple class meant as a possible main class (via manifest) to report the + * implementation version of the trove4j jar. + *

+ * This may be useful to ask feedback WITH build version information + *

+ * The Main-Class entry in the manifest.mf should be set during the build as + * well as the Implementation-Version manifest attribute should be set as well. + *

+ * Created by IntelliJ IDEA. User: Johan Parent Date: 3/03/11 Time: 22:10 + */ +public class Version { + public static void main(String[] args) { + System.out.println(getVersion()); + } + + /** + * Returns the implementation version of trove4j. Intended for applications + * wanting to return the version of trove4j they are using + *

+ * NOTE: this method will only return a useful version when working with a + * trove4j jar as it requires a manifest file + * + * @return + */ + public static String getVersion() { + String version = Version.class.getPackage().getImplementationVersion(); + // + if (version != null) { + return "trove4j version " + version; + } + + return "Sorry no Implementation-Version manifest attribute available"; + } +} diff --git a/src/gnu/trove/decorator/TByteByteMapDecorator.java b/src/gnu/trove/decorator/TByteByteMapDecorator.java new file mode 100644 index 0000000..0559231 --- /dev/null +++ b/src/gnu/trove/decorator/TByteByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteByteMap; +import gnu.trove.iterator.TByteByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteByteMap to wrap. + */ + public TByteByteMapDecorator(TByteByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteByteMap instance. + */ + public TByteByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Byte key, Byte value) { + byte k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteByteMapDecorator.this.containsKey(k) && TByteByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteCharMapDecorator.java b/src/gnu/trove/decorator/TByteCharMapDecorator.java new file mode 100644 index 0000000..5545811 --- /dev/null +++ b/src/gnu/trove/decorator/TByteCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteCharMap; +import gnu.trove.iterator.TByteCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteCharMap to wrap. + */ + public TByteCharMapDecorator(TByteCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteCharMap instance. + */ + public TByteCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Byte key, Character value) { + byte k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteCharMapDecorator.this.containsKey(k) && TByteCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteDoubleMapDecorator.java b/src/gnu/trove/decorator/TByteDoubleMapDecorator.java new file mode 100644 index 0000000..1e73ca7 --- /dev/null +++ b/src/gnu/trove/decorator/TByteDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteDoubleMap; +import gnu.trove.iterator.TByteDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteDoubleMap to wrap. + */ + public TByteDoubleMapDecorator(TByteDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteDoubleMap instance. + */ + public TByteDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Byte key, Double value) { + byte k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteDoubleMapDecorator.this.containsKey(k) && TByteDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteFloatMapDecorator.java b/src/gnu/trove/decorator/TByteFloatMapDecorator.java new file mode 100644 index 0000000..3a21ac5 --- /dev/null +++ b/src/gnu/trove/decorator/TByteFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteFloatMap; +import gnu.trove.iterator.TByteFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteFloatMap to wrap. + */ + public TByteFloatMapDecorator(TByteFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteFloatMap instance. + */ + public TByteFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Byte key, Float value) { + byte k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteFloatMapDecorator.this.containsKey(k) && TByteFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteIntMapDecorator.java b/src/gnu/trove/decorator/TByteIntMapDecorator.java new file mode 100644 index 0000000..f9534fd --- /dev/null +++ b/src/gnu/trove/decorator/TByteIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteIntMap; +import gnu.trove.iterator.TByteIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteIntMap to wrap. + */ + public TByteIntMapDecorator(TByteIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteIntMap instance. + */ + public TByteIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Byte key, Integer value) { + byte k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteIntMapDecorator.this.containsKey(k) && TByteIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteListDecorator.java b/src/gnu/trove/decorator/TByteListDecorator.java new file mode 100644 index 0000000..1945773 --- /dev/null +++ b/src/gnu/trove/decorator/TByteListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TByteList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteList conform to the java.util.List API. + * This class simply decorates an underlying TByteList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TByteListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TByteList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TByteList to wrap. + */ + public TByteListDecorator(TByteList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TByteList instance. + */ + public TByteList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Byte get(int index) { + byte value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Byte.valueOf(value); + } + + @Override + public Byte set(int index, Byte value) { + byte previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Byte.valueOf(previous_value); + } + + @Override + public void add(int index, Byte value) { + list.insert(index, value.byteValue()); + } + + @Override + public Byte remove(int index) { + byte previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Byte.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TByteList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TByteLongMapDecorator.java b/src/gnu/trove/decorator/TByteLongMapDecorator.java new file mode 100644 index 0000000..c7e1ace --- /dev/null +++ b/src/gnu/trove/decorator/TByteLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteLongMap; +import gnu.trove.iterator.TByteLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteLongMap to wrap. + */ + public TByteLongMapDecorator(TByteLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteLongMap instance. + */ + public TByteLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Byte key, Long value) { + byte k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteLongMapDecorator.this.containsKey(k) && TByteLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteObjectMapDecorator.java b/src/gnu/trove/decorator/TByteObjectMapDecorator.java new file mode 100644 index 0000000..50d5efe --- /dev/null +++ b/src/gnu/trove/decorator/TByteObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteObjectMap; +import gnu.trove.iterator.TByteObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteObjectMap to wrap. + */ + public TByteObjectMapDecorator(TByteObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteObjectMap instance. + */ + public TByteObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Byte value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Byte key, V value) { + byte k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey((Byte) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey((Byte) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteObjectMapDecorator.this.containsKey(k) && TByteObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte k = it.key(); + final Byte key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(((Byte) key).byteValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Byte key) { + return key.byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TByteObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteSetDecorator.java b/src/gnu/trove/decorator/TByteSetDecorator.java new file mode 100644 index 0000000..3713400 --- /dev/null +++ b/src/gnu/trove/decorator/TByteSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TByteSet; +import gnu.trove.iterator.TByteIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteSet conform to the java.util.Set API. + * This class simply decorates an underlying TByteSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TByteSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TByteSet to wrap. + */ + public TByteSetDecorator(TByteSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TByteSet instance. + */ + public TByteSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Byte value) { + return value != null && _set.add(value.byteValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Byte) { + byte v = ((Byte) val).byteValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Byte && _set.remove(((Byte) value).byteValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TByteIterator it = _set.iterator(); + + @Override + public Byte next() { + return Byte.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Byte)) + return false; + return _set.contains(((Byte) o).byteValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TByteSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TByteHashSetDecorator diff --git a/src/gnu/trove/decorator/TByteShortMapDecorator.java b/src/gnu/trove/decorator/TByteShortMapDecorator.java new file mode 100644 index 0000000..9441551 --- /dev/null +++ b/src/gnu/trove/decorator/TByteShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteShortMap; +import gnu.trove.iterator.TByteShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteShortMap to wrap. + */ + public TByteShortMapDecorator(TByteShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteShortMap instance. + */ + public TByteShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Byte key, Short value) { + byte k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteShortMapDecorator.this.containsKey(k) && TByteShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharByteMapDecorator.java b/src/gnu/trove/decorator/TCharByteMapDecorator.java new file mode 100644 index 0000000..1b6a22e --- /dev/null +++ b/src/gnu/trove/decorator/TCharByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharByteMap; +import gnu.trove.iterator.TCharByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharByteMap to wrap. + */ + public TCharByteMapDecorator(TCharByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharByteMap instance. + */ + public TCharByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Character key, Byte value) { + char k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharByteMapDecorator.this.containsKey(k) && TCharByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharCharMapDecorator.java b/src/gnu/trove/decorator/TCharCharMapDecorator.java new file mode 100644 index 0000000..adeccad --- /dev/null +++ b/src/gnu/trove/decorator/TCharCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharCharMap; +import gnu.trove.iterator.TCharCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharCharMap to wrap. + */ + public TCharCharMapDecorator(TCharCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharCharMap instance. + */ + public TCharCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Character key, Character value) { + char k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharCharMapDecorator.this.containsKey(k) && TCharCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharDoubleMapDecorator.java b/src/gnu/trove/decorator/TCharDoubleMapDecorator.java new file mode 100644 index 0000000..fdfc906 --- /dev/null +++ b/src/gnu/trove/decorator/TCharDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharDoubleMap; +import gnu.trove.iterator.TCharDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharDoubleMap to wrap. + */ + public TCharDoubleMapDecorator(TCharDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharDoubleMap instance. + */ + public TCharDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Character key, Double value) { + char k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharDoubleMapDecorator.this.containsKey(k) && TCharDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharFloatMapDecorator.java b/src/gnu/trove/decorator/TCharFloatMapDecorator.java new file mode 100644 index 0000000..a11dc2d --- /dev/null +++ b/src/gnu/trove/decorator/TCharFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharFloatMap; +import gnu.trove.iterator.TCharFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharFloatMap to wrap. + */ + public TCharFloatMapDecorator(TCharFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharFloatMap instance. + */ + public TCharFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Character key, Float value) { + char k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharFloatMapDecorator.this.containsKey(k) && TCharFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharIntMapDecorator.java b/src/gnu/trove/decorator/TCharIntMapDecorator.java new file mode 100644 index 0000000..07b25c8 --- /dev/null +++ b/src/gnu/trove/decorator/TCharIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharIntMap; +import gnu.trove.iterator.TCharIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharIntMap to wrap. + */ + public TCharIntMapDecorator(TCharIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharIntMap instance. + */ + public TCharIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Character key, Integer value) { + char k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharIntMapDecorator.this.containsKey(k) && TCharIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharListDecorator.java b/src/gnu/trove/decorator/TCharListDecorator.java new file mode 100644 index 0000000..6caa4ab --- /dev/null +++ b/src/gnu/trove/decorator/TCharListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TCharList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharList conform to the java.util.List API. + * This class simply decorates an underlying TCharList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TCharListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TCharList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TCharList to wrap. + */ + public TCharListDecorator(TCharList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TCharList instance. + */ + public TCharList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Character get(int index) { + char value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Character.valueOf(value); + } + + @Override + public Character set(int index, Character value) { + char previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Character.valueOf(previous_value); + } + + @Override + public void add(int index, Character value) { + list.insert(index, value.charValue()); + } + + @Override + public Character remove(int index) { + char previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Character.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TCharList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TCharLongMapDecorator.java b/src/gnu/trove/decorator/TCharLongMapDecorator.java new file mode 100644 index 0000000..9c8de19 --- /dev/null +++ b/src/gnu/trove/decorator/TCharLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharLongMap; +import gnu.trove.iterator.TCharLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharLongMap to wrap. + */ + public TCharLongMapDecorator(TCharLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharLongMap instance. + */ + public TCharLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Character key, Long value) { + char k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharLongMapDecorator.this.containsKey(k) && TCharLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharObjectMapDecorator.java b/src/gnu/trove/decorator/TCharObjectMapDecorator.java new file mode 100644 index 0000000..55a4910 --- /dev/null +++ b/src/gnu/trove/decorator/TCharObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharObjectMap; +import gnu.trove.iterator.TCharObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharObjectMap to wrap. + */ + public TCharObjectMapDecorator(TCharObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharObjectMap instance. + */ + public TCharObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Character value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Character key, V value) { + char k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey((Character) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey((Character) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharObjectMapDecorator.this.containsKey(k) && TCharObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char k = it.key(); + final Character key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(((Character) key).charValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Character key) { + return key.charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TCharObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharSetDecorator.java b/src/gnu/trove/decorator/TCharSetDecorator.java new file mode 100644 index 0000000..8209ea9 --- /dev/null +++ b/src/gnu/trove/decorator/TCharSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TCharSet; +import gnu.trove.iterator.TCharIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharSet conform to the java.util.Set API. + * This class simply decorates an underlying TCharSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TCharSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TCharSet to wrap. + */ + public TCharSetDecorator(TCharSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TCharSet instance. + */ + public TCharSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Character value) { + return value != null && _set.add(value.charValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Character) { + char v = ((Character) val).charValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Character && _set.remove(((Character) value).charValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TCharIterator it = _set.iterator(); + + @Override + public Character next() { + return Character.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Character)) + return false; + return _set.contains(((Character) o).charValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TCharSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TCharHashSetDecorator diff --git a/src/gnu/trove/decorator/TCharShortMapDecorator.java b/src/gnu/trove/decorator/TCharShortMapDecorator.java new file mode 100644 index 0000000..4cbbfb1 --- /dev/null +++ b/src/gnu/trove/decorator/TCharShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharShortMap; +import gnu.trove.iterator.TCharShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharShortMap to wrap. + */ + public TCharShortMapDecorator(TCharShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharShortMap instance. + */ + public TCharShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Character key, Short value) { + char k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharShortMapDecorator.this.containsKey(k) && TCharShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleByteMapDecorator.java b/src/gnu/trove/decorator/TDoubleByteMapDecorator.java new file mode 100644 index 0000000..0ff4c96 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleByteMap; +import gnu.trove.iterator.TDoubleByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleByteMap to wrap. + */ + public TDoubleByteMapDecorator(TDoubleByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleByteMap instance. + */ + public TDoubleByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Double key, Byte value) { + double k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleByteMapDecorator.this.containsKey(k) && TDoubleByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleCharMapDecorator.java b/src/gnu/trove/decorator/TDoubleCharMapDecorator.java new file mode 100644 index 0000000..07dbd1f --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleCharMap; +import gnu.trove.iterator.TDoubleCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleCharMap to wrap. + */ + public TDoubleCharMapDecorator(TDoubleCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleCharMap instance. + */ + public TDoubleCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Double key, Character value) { + double k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleCharMapDecorator.this.containsKey(k) && TDoubleCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleDoubleMapDecorator.java b/src/gnu/trove/decorator/TDoubleDoubleMapDecorator.java new file mode 100644 index 0000000..5ffaf32 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleDoubleMapDecorator.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleDoubleMap; +import gnu.trove.iterator.TDoubleDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleDoubleMap conform to the + * java.util.Map API. This class simply decorates an underlying + * TDoubleDoubleMap and translates the Object-based APIs into their Trove + * primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleDoubleMap to wrap. + */ + public TDoubleDoubleMapDecorator(TDoubleDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleDoubleMap instance. + */ + public TDoubleDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Double key, Double value) { + double k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleDoubleMapDecorator.this.containsKey(k) + && TDoubleDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleFloatMapDecorator.java b/src/gnu/trove/decorator/TDoubleFloatMapDecorator.java new file mode 100644 index 0000000..ec00a08 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleFloatMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleFloatMap; +import gnu.trove.iterator.TDoubleFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleFloatMap to wrap. + */ + public TDoubleFloatMapDecorator(TDoubleFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleFloatMap instance. + */ + public TDoubleFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Double key, Float value) { + double k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleFloatMapDecorator.this.containsKey(k) + && TDoubleFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleIntMapDecorator.java b/src/gnu/trove/decorator/TDoubleIntMapDecorator.java new file mode 100644 index 0000000..afbc5fc --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleIntMap; +import gnu.trove.iterator.TDoubleIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleIntMap to wrap. + */ + public TDoubleIntMapDecorator(TDoubleIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleIntMap instance. + */ + public TDoubleIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Double key, Integer value) { + double k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleIntMapDecorator.this.containsKey(k) && TDoubleIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleListDecorator.java b/src/gnu/trove/decorator/TDoubleListDecorator.java new file mode 100644 index 0000000..f950ae9 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TDoubleList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleList conform to the java.util.List + * API. This class simply decorates an underlying TDoubleList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TDoubleListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TDoubleList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TDoubleList to wrap. + */ + public TDoubleListDecorator(TDoubleList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TDoubleList instance. + */ + public TDoubleList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Double get(int index) { + double value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Double.valueOf(value); + } + + @Override + public Double set(int index, Double value) { + double previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Double.valueOf(previous_value); + } + + @Override + public void add(int index, Double value) { + list.insert(index, value.doubleValue()); + } + + @Override + public Double remove(int index) { + double previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Double.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TDoubleList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TDoubleLongMapDecorator.java b/src/gnu/trove/decorator/TDoubleLongMapDecorator.java new file mode 100644 index 0000000..63762e4 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleLongMap; +import gnu.trove.iterator.TDoubleLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleLongMap to wrap. + */ + public TDoubleLongMapDecorator(TDoubleLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleLongMap instance. + */ + public TDoubleLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Double key, Long value) { + double k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleLongMapDecorator.this.containsKey(k) && TDoubleLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleObjectMapDecorator.java b/src/gnu/trove/decorator/TDoubleObjectMapDecorator.java new file mode 100644 index 0000000..51ee6e5 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleObjectMapDecorator.java @@ -0,0 +1,376 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleObjectMap; +import gnu.trove.iterator.TDoubleObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleObjectMap conform to the + * java.util.Map API. This class simply decorates an underlying + * TDoubleObjectMap and translates the Object-based APIs into their Trove + * primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleObjectMap to wrap. + */ + public TDoubleObjectMapDecorator(TDoubleObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleObjectMap instance. + */ + public TDoubleObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Double value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Double key, V value) { + double k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey((Double) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey((Double) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleObjectMapDecorator.this.containsKey(k) + && TDoubleObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double k = it.key(); + final Double key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(((Double) key).doubleValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Double key) { + return key.doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TDoubleObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleSetDecorator.java b/src/gnu/trove/decorator/TDoubleSetDecorator.java new file mode 100644 index 0000000..48a8918 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TDoubleSet; +import gnu.trove.iterator.TDoubleIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleSet conform to the java.util.Set API. + * This class simply decorates an underlying TDoubleSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TDoubleSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TDoubleSet to wrap. + */ + public TDoubleSetDecorator(TDoubleSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TDoubleSet instance. + */ + public TDoubleSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Double value) { + return value != null && _set.add(value.doubleValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Double) { + double v = ((Double) val).doubleValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Double && _set.remove(((Double) value).doubleValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TDoubleIterator it = _set.iterator(); + + @Override + public Double next() { + return Double.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Double)) + return false; + return _set.contains(((Double) o).doubleValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TDoubleSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TDoubleHashSetDecorator diff --git a/src/gnu/trove/decorator/TDoubleShortMapDecorator.java b/src/gnu/trove/decorator/TDoubleShortMapDecorator.java new file mode 100644 index 0000000..83d0bac --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleShortMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleShortMap; +import gnu.trove.iterator.TDoubleShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleShortMap to wrap. + */ + public TDoubleShortMapDecorator(TDoubleShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleShortMap instance. + */ + public TDoubleShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Double key, Short value) { + double k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleShortMapDecorator.this.containsKey(k) + && TDoubleShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatByteMapDecorator.java b/src/gnu/trove/decorator/TFloatByteMapDecorator.java new file mode 100644 index 0000000..57b7bc9 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatByteMap; +import gnu.trove.iterator.TFloatByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatByteMap to wrap. + */ + public TFloatByteMapDecorator(TFloatByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatByteMap instance. + */ + public TFloatByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Float key, Byte value) { + float k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatByteMapDecorator.this.containsKey(k) && TFloatByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatCharMapDecorator.java b/src/gnu/trove/decorator/TFloatCharMapDecorator.java new file mode 100644 index 0000000..6947065 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatCharMap; +import gnu.trove.iterator.TFloatCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatCharMap to wrap. + */ + public TFloatCharMapDecorator(TFloatCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatCharMap instance. + */ + public TFloatCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Float key, Character value) { + float k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatCharMapDecorator.this.containsKey(k) && TFloatCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatDoubleMapDecorator.java b/src/gnu/trove/decorator/TFloatDoubleMapDecorator.java new file mode 100644 index 0000000..3e59e2a --- /dev/null +++ b/src/gnu/trove/decorator/TFloatDoubleMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatDoubleMap; +import gnu.trove.iterator.TFloatDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatDoubleMap to wrap. + */ + public TFloatDoubleMapDecorator(TFloatDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatDoubleMap instance. + */ + public TFloatDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Float key, Double value) { + float k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatDoubleMapDecorator.this.containsKey(k) + && TFloatDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatFloatMapDecorator.java b/src/gnu/trove/decorator/TFloatFloatMapDecorator.java new file mode 100644 index 0000000..8f9296f --- /dev/null +++ b/src/gnu/trove/decorator/TFloatFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatFloatMap; +import gnu.trove.iterator.TFloatFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatFloatMap to wrap. + */ + public TFloatFloatMapDecorator(TFloatFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatFloatMap instance. + */ + public TFloatFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Float key, Float value) { + float k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatFloatMapDecorator.this.containsKey(k) && TFloatFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatIntMapDecorator.java b/src/gnu/trove/decorator/TFloatIntMapDecorator.java new file mode 100644 index 0000000..c9166c1 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatIntMap; +import gnu.trove.iterator.TFloatIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatIntMap to wrap. + */ + public TFloatIntMapDecorator(TFloatIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatIntMap instance. + */ + public TFloatIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Float key, Integer value) { + float k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatIntMapDecorator.this.containsKey(k) && TFloatIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatListDecorator.java b/src/gnu/trove/decorator/TFloatListDecorator.java new file mode 100644 index 0000000..d9838aa --- /dev/null +++ b/src/gnu/trove/decorator/TFloatListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TFloatList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatList conform to the java.util.List + * API. This class simply decorates an underlying TFloatList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TFloatListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TFloatList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TFloatList to wrap. + */ + public TFloatListDecorator(TFloatList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TFloatList instance. + */ + public TFloatList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Float get(int index) { + float value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Float.valueOf(value); + } + + @Override + public Float set(int index, Float value) { + float previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Float.valueOf(previous_value); + } + + @Override + public void add(int index, Float value) { + list.insert(index, value.floatValue()); + } + + @Override + public Float remove(int index) { + float previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Float.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TFloatList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TFloatLongMapDecorator.java b/src/gnu/trove/decorator/TFloatLongMapDecorator.java new file mode 100644 index 0000000..9a33c27 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatLongMap; +import gnu.trove.iterator.TFloatLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatLongMap to wrap. + */ + public TFloatLongMapDecorator(TFloatLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatLongMap instance. + */ + public TFloatLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Float key, Long value) { + float k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatLongMapDecorator.this.containsKey(k) && TFloatLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatObjectMapDecorator.java b/src/gnu/trove/decorator/TFloatObjectMapDecorator.java new file mode 100644 index 0000000..e3e18af --- /dev/null +++ b/src/gnu/trove/decorator/TFloatObjectMapDecorator.java @@ -0,0 +1,375 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatObjectMap; +import gnu.trove.iterator.TFloatObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatObjectMap to wrap. + */ + public TFloatObjectMapDecorator(TFloatObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatObjectMap instance. + */ + public TFloatObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Float value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Float key, V value) { + float k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey((Float) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey((Float) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatObjectMapDecorator.this.containsKey(k) + && TFloatObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float k = it.key(); + final Float key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(((Float) key).floatValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Float key) { + return key.floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TFloatObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatSetDecorator.java b/src/gnu/trove/decorator/TFloatSetDecorator.java new file mode 100644 index 0000000..0f20ce0 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TFloatSet; +import gnu.trove.iterator.TFloatIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatSet conform to the java.util.Set API. + * This class simply decorates an underlying TFloatSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TFloatSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TFloatSet to wrap. + */ + public TFloatSetDecorator(TFloatSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TFloatSet instance. + */ + public TFloatSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Float value) { + return value != null && _set.add(value.floatValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Float) { + float v = ((Float) val).floatValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Float && _set.remove(((Float) value).floatValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TFloatIterator it = _set.iterator(); + + @Override + public Float next() { + return Float.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Float)) + return false; + return _set.contains(((Float) o).floatValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TFloatSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TFloatHashSetDecorator diff --git a/src/gnu/trove/decorator/TFloatShortMapDecorator.java b/src/gnu/trove/decorator/TFloatShortMapDecorator.java new file mode 100644 index 0000000..84ed98c --- /dev/null +++ b/src/gnu/trove/decorator/TFloatShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatShortMap; +import gnu.trove.iterator.TFloatShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatShortMap to wrap. + */ + public TFloatShortMapDecorator(TFloatShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatShortMap instance. + */ + public TFloatShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Float key, Short value) { + float k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatShortMapDecorator.this.containsKey(k) && TFloatShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntByteMapDecorator.java b/src/gnu/trove/decorator/TIntByteMapDecorator.java new file mode 100644 index 0000000..f6541ad --- /dev/null +++ b/src/gnu/trove/decorator/TIntByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntByteMap; +import gnu.trove.iterator.TIntByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntByteMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntByteMap to wrap. + */ + public TIntByteMapDecorator(TIntByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntByteMap instance. + */ + public TIntByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Integer key, Byte value) { + int k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntByteMapDecorator.this.containsKey(k) && TIntByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntCharMapDecorator.java b/src/gnu/trove/decorator/TIntCharMapDecorator.java new file mode 100644 index 0000000..56c8a56 --- /dev/null +++ b/src/gnu/trove/decorator/TIntCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntCharMap; +import gnu.trove.iterator.TIntCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntCharMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntCharMap to wrap. + */ + public TIntCharMapDecorator(TIntCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntCharMap instance. + */ + public TIntCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Integer key, Character value) { + int k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntCharMapDecorator.this.containsKey(k) && TIntCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntDoubleMapDecorator.java b/src/gnu/trove/decorator/TIntDoubleMapDecorator.java new file mode 100644 index 0000000..e070654 --- /dev/null +++ b/src/gnu/trove/decorator/TIntDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntDoubleMap; +import gnu.trove.iterator.TIntDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntDoubleMap to wrap. + */ + public TIntDoubleMapDecorator(TIntDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntDoubleMap instance. + */ + public TIntDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Integer key, Double value) { + int k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntDoubleMapDecorator.this.containsKey(k) && TIntDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntFloatMapDecorator.java b/src/gnu/trove/decorator/TIntFloatMapDecorator.java new file mode 100644 index 0000000..cea602b --- /dev/null +++ b/src/gnu/trove/decorator/TIntFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntFloatMap; +import gnu.trove.iterator.TIntFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntFloatMap to wrap. + */ + public TIntFloatMapDecorator(TIntFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntFloatMap instance. + */ + public TIntFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Integer key, Float value) { + int k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntFloatMapDecorator.this.containsKey(k) && TIntFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntIntMapDecorator.java b/src/gnu/trove/decorator/TIntIntMapDecorator.java new file mode 100644 index 0000000..f939706 --- /dev/null +++ b/src/gnu/trove/decorator/TIntIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntIntMap; +import gnu.trove.iterator.TIntIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntIntMap conform to the java.util.Map API. + * This class simply decorates an underlying TIntIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntIntMap to wrap. + */ + public TIntIntMapDecorator(TIntIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntIntMap instance. + */ + public TIntIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Integer key, Integer value) { + int k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntIntMapDecorator.this.containsKey(k) && TIntIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntListDecorator.java b/src/gnu/trove/decorator/TIntListDecorator.java new file mode 100644 index 0000000..e07e9b5 --- /dev/null +++ b/src/gnu/trove/decorator/TIntListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TIntList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntList conform to the java.util.List API. + * This class simply decorates an underlying TIntList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TIntListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TIntList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TIntList to wrap. + */ + public TIntListDecorator(TIntList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TIntList instance. + */ + public TIntList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Integer get(int index) { + int value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Integer.valueOf(value); + } + + @Override + public Integer set(int index, Integer value) { + int previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Integer.valueOf(previous_value); + } + + @Override + public void add(int index, Integer value) { + list.insert(index, value.intValue()); + } + + @Override + public Integer remove(int index) { + int previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Integer.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TIntList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TIntLongMapDecorator.java b/src/gnu/trove/decorator/TIntLongMapDecorator.java new file mode 100644 index 0000000..44b8cbd --- /dev/null +++ b/src/gnu/trove/decorator/TIntLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntLongMap; +import gnu.trove.iterator.TIntLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntLongMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntLongMap to wrap. + */ + public TIntLongMapDecorator(TIntLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntLongMap instance. + */ + public TIntLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Integer key, Long value) { + int k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntLongMapDecorator.this.containsKey(k) && TIntLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntObjectMapDecorator.java b/src/gnu/trove/decorator/TIntObjectMapDecorator.java new file mode 100644 index 0000000..f1122d8 --- /dev/null +++ b/src/gnu/trove/decorator/TIntObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntObjectMap; +import gnu.trove.iterator.TIntObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntObjectMap to wrap. + */ + public TIntObjectMapDecorator(TIntObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntObjectMap instance. + */ + public TIntObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Integer value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Integer key, V value) { + int k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey((Integer) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey((Integer) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntObjectMapDecorator.this.containsKey(k) && TIntObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int k = it.key(); + final Integer key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(((Integer) key).intValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Integer key) { + return key.intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TIntObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntSetDecorator.java b/src/gnu/trove/decorator/TIntSetDecorator.java new file mode 100644 index 0000000..fa721c2 --- /dev/null +++ b/src/gnu/trove/decorator/TIntSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TIntSet; +import gnu.trove.iterator.TIntIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntSet conform to the java.util.Set API. + * This class simply decorates an underlying TIntSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TIntSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TIntSet to wrap. + */ + public TIntSetDecorator(TIntSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TIntSet instance. + */ + public TIntSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Integer value) { + return value != null && _set.add(value.intValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Integer) { + int v = ((Integer) val).intValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Integer && _set.remove(((Integer) value).intValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TIntIterator it = _set.iterator(); + + @Override + public Integer next() { + return Integer.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Integer)) + return false; + return _set.contains(((Integer) o).intValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TIntSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TIntHashSetDecorator diff --git a/src/gnu/trove/decorator/TIntShortMapDecorator.java b/src/gnu/trove/decorator/TIntShortMapDecorator.java new file mode 100644 index 0000000..f963a73 --- /dev/null +++ b/src/gnu/trove/decorator/TIntShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntShortMap; +import gnu.trove.iterator.TIntShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntShortMap to wrap. + */ + public TIntShortMapDecorator(TIntShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntShortMap instance. + */ + public TIntShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Integer key, Short value) { + int k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntShortMapDecorator.this.containsKey(k) && TIntShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongByteMapDecorator.java b/src/gnu/trove/decorator/TLongByteMapDecorator.java new file mode 100644 index 0000000..6195e49 --- /dev/null +++ b/src/gnu/trove/decorator/TLongByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongByteMap; +import gnu.trove.iterator.TLongByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongByteMap to wrap. + */ + public TLongByteMapDecorator(TLongByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongByteMap instance. + */ + public TLongByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Long key, Byte value) { + long k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongByteMapDecorator.this.containsKey(k) && TLongByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongCharMapDecorator.java b/src/gnu/trove/decorator/TLongCharMapDecorator.java new file mode 100644 index 0000000..d1be8f0 --- /dev/null +++ b/src/gnu/trove/decorator/TLongCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongCharMap; +import gnu.trove.iterator.TLongCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongCharMap to wrap. + */ + public TLongCharMapDecorator(TLongCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongCharMap instance. + */ + public TLongCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Long key, Character value) { + long k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongCharMapDecorator.this.containsKey(k) && TLongCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongDoubleMapDecorator.java b/src/gnu/trove/decorator/TLongDoubleMapDecorator.java new file mode 100644 index 0000000..909049b --- /dev/null +++ b/src/gnu/trove/decorator/TLongDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongDoubleMap; +import gnu.trove.iterator.TLongDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongDoubleMap to wrap. + */ + public TLongDoubleMapDecorator(TLongDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongDoubleMap instance. + */ + public TLongDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Long key, Double value) { + long k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongDoubleMapDecorator.this.containsKey(k) && TLongDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongFloatMapDecorator.java b/src/gnu/trove/decorator/TLongFloatMapDecorator.java new file mode 100644 index 0000000..7fe66d1 --- /dev/null +++ b/src/gnu/trove/decorator/TLongFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongFloatMap; +import gnu.trove.iterator.TLongFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongFloatMap to wrap. + */ + public TLongFloatMapDecorator(TLongFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongFloatMap instance. + */ + public TLongFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Long key, Float value) { + long k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongFloatMapDecorator.this.containsKey(k) && TLongFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongIntMapDecorator.java b/src/gnu/trove/decorator/TLongIntMapDecorator.java new file mode 100644 index 0000000..a255164 --- /dev/null +++ b/src/gnu/trove/decorator/TLongIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongIntMap; +import gnu.trove.iterator.TLongIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongIntMap to wrap. + */ + public TLongIntMapDecorator(TLongIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongIntMap instance. + */ + public TLongIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Long key, Integer value) { + long k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongIntMapDecorator.this.containsKey(k) && TLongIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongListDecorator.java b/src/gnu/trove/decorator/TLongListDecorator.java new file mode 100644 index 0000000..dcd9faa --- /dev/null +++ b/src/gnu/trove/decorator/TLongListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TLongList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongList conform to the java.util.List API. + * This class simply decorates an underlying TLongList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TLongListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TLongList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TLongList to wrap. + */ + public TLongListDecorator(TLongList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TLongList instance. + */ + public TLongList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Long get(int index) { + long value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Long.valueOf(value); + } + + @Override + public Long set(int index, Long value) { + long previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Long.valueOf(previous_value); + } + + @Override + public void add(int index, Long value) { + list.insert(index, value.longValue()); + } + + @Override + public Long remove(int index) { + long previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Long.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TLongList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TLongLongMapDecorator.java b/src/gnu/trove/decorator/TLongLongMapDecorator.java new file mode 100644 index 0000000..38fe65c --- /dev/null +++ b/src/gnu/trove/decorator/TLongLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongLongMap; +import gnu.trove.iterator.TLongLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongLongMap to wrap. + */ + public TLongLongMapDecorator(TLongLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongLongMap instance. + */ + public TLongLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Long key, Long value) { + long k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongLongMapDecorator.this.containsKey(k) && TLongLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongObjectMapDecorator.java b/src/gnu/trove/decorator/TLongObjectMapDecorator.java new file mode 100644 index 0000000..c59e71f --- /dev/null +++ b/src/gnu/trove/decorator/TLongObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongObjectMap; +import gnu.trove.iterator.TLongObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongObjectMap to wrap. + */ + public TLongObjectMapDecorator(TLongObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongObjectMap instance. + */ + public TLongObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Long value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Long key, V value) { + long k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey((Long) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey((Long) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongObjectMapDecorator.this.containsKey(k) && TLongObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long k = it.key(); + final Long key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(((Long) key).longValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Long key) { + return key.longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TLongObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongSetDecorator.java b/src/gnu/trove/decorator/TLongSetDecorator.java new file mode 100644 index 0000000..7b4f331 --- /dev/null +++ b/src/gnu/trove/decorator/TLongSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TLongSet; +import gnu.trove.iterator.TLongIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongSet conform to the java.util.Set API. + * This class simply decorates an underlying TLongSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TLongSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TLongSet to wrap. + */ + public TLongSetDecorator(TLongSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TLongSet instance. + */ + public TLongSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Long value) { + return value != null && _set.add(value.longValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Long) { + long v = ((Long) val).longValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Long && _set.remove(((Long) value).longValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TLongIterator it = _set.iterator(); + + @Override + public Long next() { + return Long.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Long)) + return false; + return _set.contains(((Long) o).longValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TLongSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TLongHashSetDecorator diff --git a/src/gnu/trove/decorator/TLongShortMapDecorator.java b/src/gnu/trove/decorator/TLongShortMapDecorator.java new file mode 100644 index 0000000..1fba4f7 --- /dev/null +++ b/src/gnu/trove/decorator/TLongShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongShortMap; +import gnu.trove.iterator.TLongShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongShortMap to wrap. + */ + public TLongShortMapDecorator(TLongShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongShortMap instance. + */ + public TLongShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Long key, Short value) { + long k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongShortMapDecorator.this.containsKey(k) && TLongShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TObjectByteMapDecorator.java b/src/gnu/trove/decorator/TObjectByteMapDecorator.java new file mode 100644 index 0000000..16cf2dc --- /dev/null +++ b/src/gnu/trove/decorator/TObjectByteMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectByteMap; +import gnu.trove.iterator.TObjectByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectByteMap to wrap. + */ + public TObjectByteMapDecorator(TObjectByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectByteMap instance. + */ + public TObjectByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Byte value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Byte put(K key, Byte value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + byte v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Byte remove(Object key) { + byte v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectByteMapDecorator.this.containsKey(k) && TObjectByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Byte v = wrapValue(it.value()); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectByteMapDecorator diff --git a/src/gnu/trove/decorator/TObjectCharMapDecorator.java b/src/gnu/trove/decorator/TObjectCharMapDecorator.java new file mode 100644 index 0000000..f01e5ae --- /dev/null +++ b/src/gnu/trove/decorator/TObjectCharMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectCharMap; +import gnu.trove.iterator.TObjectCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectCharMap to wrap. + */ + public TObjectCharMapDecorator(TObjectCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectCharMap instance. + */ + public TObjectCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Character value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Character put(K key, Character value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + char v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Character remove(Object key) { + char v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectCharMapDecorator.this.containsKey(k) && TObjectCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Character v = wrapValue(it.value()); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectCharMapDecorator diff --git a/src/gnu/trove/decorator/TObjectDoubleMapDecorator.java b/src/gnu/trove/decorator/TObjectDoubleMapDecorator.java new file mode 100644 index 0000000..333a226 --- /dev/null +++ b/src/gnu/trove/decorator/TObjectDoubleMapDecorator.java @@ -0,0 +1,367 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectDoubleMap; +import gnu.trove.iterator.TObjectDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectDoubleMap conform to the + * java.util.Map API. This class simply decorates an underlying + * TObjectDoubleMap and translates the Object-based APIs into their Trove + * primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectDoubleMap to wrap. + */ + public TObjectDoubleMapDecorator(TObjectDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectDoubleMap instance. + */ + public TObjectDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Double value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Double put(K key, Double value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + double v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Double remove(Object key) { + double v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectDoubleMapDecorator.this.containsKey(k) + && TObjectDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Double v = wrapValue(it.value()); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectDoubleMapDecorator diff --git a/src/gnu/trove/decorator/TObjectFloatMapDecorator.java b/src/gnu/trove/decorator/TObjectFloatMapDecorator.java new file mode 100644 index 0000000..3b53d6d --- /dev/null +++ b/src/gnu/trove/decorator/TObjectFloatMapDecorator.java @@ -0,0 +1,366 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectFloatMap; +import gnu.trove.iterator.TObjectFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectFloatMap to wrap. + */ + public TObjectFloatMapDecorator(TObjectFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectFloatMap instance. + */ + public TObjectFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Float value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Float put(K key, Float value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + float v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Float remove(Object key) { + float v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectFloatMapDecorator.this.containsKey(k) + && TObjectFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Float v = wrapValue(it.value()); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectFloatMapDecorator diff --git a/src/gnu/trove/decorator/TObjectIntMapDecorator.java b/src/gnu/trove/decorator/TObjectIntMapDecorator.java new file mode 100644 index 0000000..c03782e --- /dev/null +++ b/src/gnu/trove/decorator/TObjectIntMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectIntMap; +import gnu.trove.iterator.TObjectIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectIntMap to wrap. + */ + public TObjectIntMapDecorator(TObjectIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectIntMap instance. + */ + public TObjectIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Integer value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(K key, Integer value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + int v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Integer remove(Object key) { + int v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectIntMapDecorator.this.containsKey(k) && TObjectIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Integer v = wrapValue(it.value()); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectIntMapDecorator diff --git a/src/gnu/trove/decorator/TObjectLongMapDecorator.java b/src/gnu/trove/decorator/TObjectLongMapDecorator.java new file mode 100644 index 0000000..b714c92 --- /dev/null +++ b/src/gnu/trove/decorator/TObjectLongMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectLongMap; +import gnu.trove.iterator.TObjectLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectLongMap to wrap. + */ + public TObjectLongMapDecorator(TObjectLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectLongMap instance. + */ + public TObjectLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Long value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Long put(K key, Long value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + long v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Long remove(Object key) { + long v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectLongMapDecorator.this.containsKey(k) && TObjectLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Long v = wrapValue(it.value()); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectLongMapDecorator diff --git a/src/gnu/trove/decorator/TObjectShortMapDecorator.java b/src/gnu/trove/decorator/TObjectShortMapDecorator.java new file mode 100644 index 0000000..80d6c2a --- /dev/null +++ b/src/gnu/trove/decorator/TObjectShortMapDecorator.java @@ -0,0 +1,366 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectShortMap; +import gnu.trove.iterator.TObjectShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectShortMap to wrap. + */ + public TObjectShortMapDecorator(TObjectShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectShortMap instance. + */ + public TObjectShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Short value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Short put(K key, Short value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + short v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Short remove(Object key) { + short v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectShortMapDecorator.this.containsKey(k) + && TObjectShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Short v = wrapValue(it.value()); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectShortMapDecorator diff --git a/src/gnu/trove/decorator/TShortByteMapDecorator.java b/src/gnu/trove/decorator/TShortByteMapDecorator.java new file mode 100644 index 0000000..307df19 --- /dev/null +++ b/src/gnu/trove/decorator/TShortByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortByteMap; +import gnu.trove.iterator.TShortByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortByteMap to wrap. + */ + public TShortByteMapDecorator(TShortByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortByteMap instance. + */ + public TShortByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Short key, Byte value) { + short k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortByteMapDecorator.this.containsKey(k) && TShortByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortCharMapDecorator.java b/src/gnu/trove/decorator/TShortCharMapDecorator.java new file mode 100644 index 0000000..59cdfe6 --- /dev/null +++ b/src/gnu/trove/decorator/TShortCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortCharMap; +import gnu.trove.iterator.TShortCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortCharMap to wrap. + */ + public TShortCharMapDecorator(TShortCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortCharMap instance. + */ + public TShortCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Short key, Character value) { + short k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortCharMapDecorator.this.containsKey(k) && TShortCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortDoubleMapDecorator.java b/src/gnu/trove/decorator/TShortDoubleMapDecorator.java new file mode 100644 index 0000000..54ee734 --- /dev/null +++ b/src/gnu/trove/decorator/TShortDoubleMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortDoubleMap; +import gnu.trove.iterator.TShortDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortDoubleMap to wrap. + */ + public TShortDoubleMapDecorator(TShortDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortDoubleMap instance. + */ + public TShortDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Short key, Double value) { + short k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortDoubleMapDecorator.this.containsKey(k) + && TShortDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortFloatMapDecorator.java b/src/gnu/trove/decorator/TShortFloatMapDecorator.java new file mode 100644 index 0000000..fef28be --- /dev/null +++ b/src/gnu/trove/decorator/TShortFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortFloatMap; +import gnu.trove.iterator.TShortFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortFloatMap to wrap. + */ + public TShortFloatMapDecorator(TShortFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortFloatMap instance. + */ + public TShortFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Short key, Float value) { + short k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortFloatMapDecorator.this.containsKey(k) && TShortFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortIntMapDecorator.java b/src/gnu/trove/decorator/TShortIntMapDecorator.java new file mode 100644 index 0000000..e4f4284 --- /dev/null +++ b/src/gnu/trove/decorator/TShortIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortIntMap; +import gnu.trove.iterator.TShortIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortIntMap to wrap. + */ + public TShortIntMapDecorator(TShortIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortIntMap instance. + */ + public TShortIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Short key, Integer value) { + short k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortIntMapDecorator.this.containsKey(k) && TShortIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortListDecorator.java b/src/gnu/trove/decorator/TShortListDecorator.java new file mode 100644 index 0000000..51f8332 --- /dev/null +++ b/src/gnu/trove/decorator/TShortListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TShortList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortList conform to the java.util.List + * API. This class simply decorates an underlying TShortList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TShortListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TShortList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TShortList to wrap. + */ + public TShortListDecorator(TShortList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TShortList instance. + */ + public TShortList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Short get(int index) { + short value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Short.valueOf(value); + } + + @Override + public Short set(int index, Short value) { + short previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Short.valueOf(previous_value); + } + + @Override + public void add(int index, Short value) { + list.insert(index, value.shortValue()); + } + + @Override + public Short remove(int index) { + short previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Short.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TShortList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TShortLongMapDecorator.java b/src/gnu/trove/decorator/TShortLongMapDecorator.java new file mode 100644 index 0000000..4c87e0b --- /dev/null +++ b/src/gnu/trove/decorator/TShortLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortLongMap; +import gnu.trove.iterator.TShortLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortLongMap to wrap. + */ + public TShortLongMapDecorator(TShortLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortLongMap instance. + */ + public TShortLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Short key, Long value) { + short k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortLongMapDecorator.this.containsKey(k) && TShortLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortObjectMapDecorator.java b/src/gnu/trove/decorator/TShortObjectMapDecorator.java new file mode 100644 index 0000000..ec3e311 --- /dev/null +++ b/src/gnu/trove/decorator/TShortObjectMapDecorator.java @@ -0,0 +1,375 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortObjectMap; +import gnu.trove.iterator.TShortObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortObjectMap to wrap. + */ + public TShortObjectMapDecorator(TShortObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortObjectMap instance. + */ + public TShortObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Short value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Short key, V value) { + short k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey((Short) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey((Short) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortObjectMapDecorator.this.containsKey(k) + && TShortObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short k = it.key(); + final Short key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(((Short) key).shortValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Short key) { + return key.shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TShortObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortSetDecorator.java b/src/gnu/trove/decorator/TShortSetDecorator.java new file mode 100644 index 0000000..20484ce --- /dev/null +++ b/src/gnu/trove/decorator/TShortSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TShortSet; +import gnu.trove.iterator.TShortIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortSet conform to the java.util.Set API. + * This class simply decorates an underlying TShortSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TShortSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TShortSet to wrap. + */ + public TShortSetDecorator(TShortSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TShortSet instance. + */ + public TShortSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Short value) { + return value != null && _set.add(value.shortValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Short) { + short v = ((Short) val).shortValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Short && _set.remove(((Short) value).shortValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TShortIterator it = _set.iterator(); + + @Override + public Short next() { + return Short.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Short)) + return false; + return _set.contains(((Short) o).shortValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TShortSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TShortHashSetDecorator diff --git a/src/gnu/trove/decorator/TShortShortMapDecorator.java b/src/gnu/trove/decorator/TShortShortMapDecorator.java new file mode 100644 index 0000000..5bb87a9 --- /dev/null +++ b/src/gnu/trove/decorator/TShortShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortShortMap; +import gnu.trove.iterator.TShortShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortShortMap to wrap. + */ + public TShortShortMapDecorator(TShortShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortShortMap instance. + */ + public TShortShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Short key, Short value) { + short k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortShortMapDecorator.this.containsKey(k) && TShortShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortShortHashMapDecorator diff --git a/src/gnu/trove/function/TByteFunction.java b/src/gnu/trove/function/TByteFunction.java new file mode 100644 index 0000000..b49e333 --- /dev/null +++ b/src/gnu/trove/function/TByteFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one byte primitive. + */ +public interface TByteFunction { + /** + * Execute this function with value + * + * @param value + * a byte input + * @return a byte result + */ + public byte execute(byte value); +} diff --git a/src/gnu/trove/function/TCharFunction.java b/src/gnu/trove/function/TCharFunction.java new file mode 100644 index 0000000..15a4441 --- /dev/null +++ b/src/gnu/trove/function/TCharFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one char primitive. + */ +public interface TCharFunction { + /** + * Execute this function with value + * + * @param value + * a char input + * @return a char result + */ + public char execute(char value); +} diff --git a/src/gnu/trove/function/TDoubleFunction.java b/src/gnu/trove/function/TDoubleFunction.java new file mode 100644 index 0000000..1c92410 --- /dev/null +++ b/src/gnu/trove/function/TDoubleFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one double primitive. + */ +public interface TDoubleFunction { + /** + * Execute this function with value + * + * @param value + * a double input + * @return a double result + */ + public double execute(double value); +} diff --git a/src/gnu/trove/function/TFloatFunction.java b/src/gnu/trove/function/TFloatFunction.java new file mode 100644 index 0000000..999ce5f --- /dev/null +++ b/src/gnu/trove/function/TFloatFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one float primitive. + */ +public interface TFloatFunction { + /** + * Execute this function with value + * + * @param value + * a float input + * @return a float result + */ + public float execute(float value); +} diff --git a/src/gnu/trove/function/TIntFunction.java b/src/gnu/trove/function/TIntFunction.java new file mode 100644 index 0000000..7246f93 --- /dev/null +++ b/src/gnu/trove/function/TIntFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one int primitive. + */ +public interface TIntFunction { + /** + * Execute this function with value + * + * @param value + * a int input + * @return a int result + */ + public int execute(int value); +} diff --git a/src/gnu/trove/function/TLongFunction.java b/src/gnu/trove/function/TLongFunction.java new file mode 100644 index 0000000..dbd6663 --- /dev/null +++ b/src/gnu/trove/function/TLongFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one long primitive. + */ +public interface TLongFunction { + /** + * Execute this function with value + * + * @param value + * a long input + * @return a long result + */ + public long execute(long value); +} diff --git a/src/gnu/trove/function/TObjectFunction.java b/src/gnu/trove/function/TObjectFunction.java new file mode 100644 index 0000000..6ecd144 --- /dev/null +++ b/src/gnu/trove/function/TObjectFunction.java @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +/** + * Interface for functions that accept and return one Object reference. + *

+ * Created: Mon Nov 5 22:19:36 2001 + * + * @author Eric D. Friedman + * @version $Id: TObjectFunction.java,v 1.1.2.1 2009/09/06 17:02:19 + * upholderoftruth Exp $ + */ + +public interface TObjectFunction { + + /** + * Execute this function with value + * + * @param value + * an Object input + * @return an Object result + */ + public R execute(T value); +}// TObjectFunction diff --git a/src/gnu/trove/function/TShortFunction.java b/src/gnu/trove/function/TShortFunction.java new file mode 100644 index 0000000..f1e20a3 --- /dev/null +++ b/src/gnu/trove/function/TShortFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one short primitive. + */ +public interface TShortFunction { + /** + * Execute this function with value + * + * @param value + * a short input + * @return a short result + */ + public short execute(short value); +} diff --git a/src/gnu/trove/impl/Constants.java b/src/gnu/trove/impl/Constants.java new file mode 100644 index 0000000..56b45a4 --- /dev/null +++ b/src/gnu/trove/impl/Constants.java @@ -0,0 +1,227 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// +package gnu.trove.impl; + +/** + * Central location for constants needed by various implementations. + */ +public class Constants { + + private static final boolean VERBOSE; + static { + boolean verbose = false; + try { + verbose = System.getProperty("gnu.trove.verbose", null) != null; + } catch (SecurityException ex) { + // ignore + } + VERBOSE = verbose; + } + + /** the default capacity for new collections */ + public static final int DEFAULT_CAPACITY = 10; + + /** the load above which rehashing occurs. */ + public static final float DEFAULT_LOAD_FACTOR = 0.5f; + + /** the default value that represents for byte types. */ + public static final byte DEFAULT_BYTE_NO_ENTRY_VALUE; + static { + byte value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.byte", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Byte.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Byte.MIN_VALUE; + else + value = Byte.valueOf(property); + + if (value > Byte.MAX_VALUE) + value = Byte.MAX_VALUE; + else if (value < Byte.MIN_VALUE) + value = Byte.MIN_VALUE; + DEFAULT_BYTE_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_BYTE_NO_ENTRY_VALUE: " + DEFAULT_BYTE_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for short types. */ + public static final short DEFAULT_SHORT_NO_ENTRY_VALUE; + static { + short value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.short", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Short.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Short.MIN_VALUE; + else + value = Short.valueOf(property); + + if (value > Short.MAX_VALUE) + value = Short.MAX_VALUE; + else if (value < Short.MIN_VALUE) + value = Short.MIN_VALUE; + DEFAULT_SHORT_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_SHORT_NO_ENTRY_VALUE: " + DEFAULT_SHORT_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for char types. */ + public static final char DEFAULT_CHAR_NO_ENTRY_VALUE; + static { + char value; + String property = "\0"; + try { + property = System.getProperty("gnu.trove.no_entry.char", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Character.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Character.MIN_VALUE; + else + value = property.toCharArray()[0]; + + if (value > Character.MAX_VALUE) + value = Character.MAX_VALUE; + else if (value < Character.MIN_VALUE) + value = Character.MIN_VALUE; + DEFAULT_CHAR_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_CHAR_NO_ENTRY_VALUE: " + Integer.valueOf(value)); + } + } + + /** the default value that represents for int types. */ + public static final int DEFAULT_INT_NO_ENTRY_VALUE; + static { + int value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.int", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Integer.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Integer.MIN_VALUE; + else + value = Integer.valueOf(property); + DEFAULT_INT_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_INT_NO_ENTRY_VALUE: " + DEFAULT_INT_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for long types. */ + public static final long DEFAULT_LONG_NO_ENTRY_VALUE; + static { + long value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.long", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Long.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Long.MIN_VALUE; + else + value = Long.valueOf(property); + DEFAULT_LONG_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_LONG_NO_ENTRY_VALUE: " + DEFAULT_LONG_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for float types. */ + public static final float DEFAULT_FLOAT_NO_ENTRY_VALUE; + static { + float value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.float", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Float.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Float.MIN_VALUE; + // Value from Float.MIN_NORMAL (introduced in 1.6) + else if ("MIN_NORMAL".equalsIgnoreCase(property)) + value = 0x1.0p-126f; + else if ("NEGATIVE_INFINITY".equalsIgnoreCase(property)) + value = Float.NEGATIVE_INFINITY; + else if ("POSITIVE_INFINITY".equalsIgnoreCase(property)) + value = Float.POSITIVE_INFINITY; + // else if ( "NaN".equalsIgnoreCase( property ) ) value = Float.NaN; + else + value = Float.valueOf(property); + DEFAULT_FLOAT_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_FLOAT_NO_ENTRY_VALUE: " + DEFAULT_FLOAT_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for double types. */ + public static final double DEFAULT_DOUBLE_NO_ENTRY_VALUE; + static { + double value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.double", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Double.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Double.MIN_VALUE; + // Value from Double.MIN_NORMAL (introduced in 1.6) + else if ("MIN_NORMAL".equalsIgnoreCase(property)) + value = 0x1.0p-1022; + else if ("NEGATIVE_INFINITY".equalsIgnoreCase(property)) + value = Double.NEGATIVE_INFINITY; + else if ("POSITIVE_INFINITY".equalsIgnoreCase(property)) + value = Double.POSITIVE_INFINITY; + // else if ( "NaN".equalsIgnoreCase( property ) ) value = Double.NaN; + else + value = Double.valueOf(property); + DEFAULT_DOUBLE_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_DOUBLE_NO_ENTRY_VALUE: " + DEFAULT_DOUBLE_NO_ENTRY_VALUE); + } + } +} diff --git a/src/gnu/trove/impl/HashFunctions.java b/src/gnu/trove/impl/HashFunctions.java new file mode 100644 index 0000000..fcfc899 --- /dev/null +++ b/src/gnu/trove/impl/HashFunctions.java @@ -0,0 +1,85 @@ +// Copyright (c) 1999 CERN - European Organization for Nuclear Research. + +// Permission to use, copy, modify, distribute and sell this software and +// its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and that +// both that copyright notice and this permission notice appear in +// supporting documentation. CERN makes no representations about the +// suitability of this software for any purpose. It is provided "as is" +// without expressed or implied warranty. + +package gnu.trove.impl; + +/** + * Provides various hash functions. + * + * @author wolfgang.hoschek@cern.ch + * @version 1.0, 09/24/99 + */ +public final class HashFunctions { + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(double value) { + assert !Double.isNaN(value) : "Values of NaN are not supported."; + + long bits = Double.doubleToLongBits(value); + return (int) (bits ^ (bits >>> 32)); + // return (int) Double.doubleToLongBits(value*663608941.737); + // this avoids excessive hashCollisions in the case values are + // of the form (1.0, 2.0, 3.0, ...) + } + + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(float value) { + assert !Float.isNaN(value) : "Values of NaN are not supported."; + + return Float.floatToIntBits(value * 663608941.737f); + // this avoids excessive hashCollisions in the case values are + // of the form (1.0, 2.0, 3.0, ...) + } + + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(int value) { + return value; + } + + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(long value) { + return ((int) (value ^ (value >>> 32))); + } + + /** + * Returns a hashcode for the specified object. + * + * @return a hash code value for the specified object. + */ + public static int hash(Object object) { + return object == null ? 0 : object.hashCode(); + } + + /** + * In profiling, it has been found to be faster to have our own local + * implementation of "ceil" rather than to call to {@link Math#ceil(double)}. + */ + public static int fastCeil(float v) { + int possible_result = (int) v; + if (v - possible_result > 0) + possible_result++; + return possible_result; + } +} diff --git a/src/gnu/trove/impl/PrimeFinder.java b/src/gnu/trove/impl/PrimeFinder.java new file mode 100644 index 0000000..9d0509d --- /dev/null +++ b/src/gnu/trove/impl/PrimeFinder.java @@ -0,0 +1,151 @@ +// Copyright (c) 1999 CERN - European Organization for Nuclear Research. + +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear in +// supporting documentation. CERN makes no representations about the +// suitability of this software for any purpose. It is provided "as is" +// without expressed or implied warranty. +package gnu.trove.impl; + +import java.util.Arrays; + +/* + * Modified for Trove to use the java.util.Arrays sort/search + * algorithms instead of those provided with colt. + */ + +/** + * Used to keep hash table capacities prime numbers. Not of interest for users; + * only for implementors of hashtables. + * + *

+ * Choosing prime numbers as hash table capacities is a good idea to keep them + * working fast, particularly under hash table expansions. + * + *

+ * However, JDK 1.2, JGL 3.1 and many other toolkits do nothing to keep + * capacities prime. This class provides efficient means to choose prime + * capacities. + * + *

+ * Choosing a prime is O(log 300) (binary search in a list of 300 + * ints). Memory requirements: 1 KB static memory. + * + * @author wolfgang.hoschek@cern.ch + * @version 1.0, 09/24/99 + */ +public final class PrimeFinder { + /** + * The largest prime this class can generate; currently equal to + * Integer.MAX_VALUE. + */ + public static final int largestPrime = Integer.MAX_VALUE; // yes, it is prime. + + /** + * The prime number list consists of 11 chunks. + * + * Each chunk contains prime numbers. + * + * A chunk starts with a prime P1. The next element is a prime P2. P2 is the + * smallest prime for which holds: P2 >= 2*P1. + * + * The next element is P3, for which the same holds with respect to P2, and so + * on. + * + * Chunks are chosen such that for any desired capacity >= 1000 the list + * includes a prime number <= desired capacity * 1.11. + * + * Therefore, primes can be retrieved which are quite close to any desired + * capacity, which in turn avoids wasting memory. + * + * For example, the list includes + * 1039,1117,1201,1277,1361,1439,1523,1597,1759,1907,2081. + * + * So if you need a prime >= 1040, you will find a prime <= 1040*1.11=1154. + * + * Chunks are chosen such that they are optimized for a hashtable growthfactor + * of 2.0; + * + * If your hashtable has such a growthfactor then, after initially "rounding to + * a prime" upon hashtable construction, it will later expand to prime + * capacities such that there exist no better primes. + * + * In total these are about 32*10=320 numbers -> 1 KB of static memory needed. + * + * If you are stingy, then delete every second or fourth chunk. + */ + + private static final int[] primeCapacities = { + // chunk #0 + largestPrime, + + // chunk #1 + 5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853, 25717, 51437, 102877, 205759, 411527, 823117, + 1646237, 3292489, 6584983, 13169977, 26339969, 52679969, 105359939, 210719881, 421439783, 842879579, + 1685759167, + + // chunk #2 + 433, 877, 1759, 3527, 7057, 14143, 28289, 56591, 113189, 226379, 452759, 905551, 1811107, 3622219, 7244441, + 14488931, 28977863, 57955739, 115911563, 231823147, 463646329, 927292699, 1854585413, + + // chunk #3 + 953, 1907, 3821, 7643, 15287, 30577, 61169, 122347, 244703, 489407, 978821, 1957651, 3915341, 7830701, + 15661423, 31322867, 62645741, 125291483, 250582987, 501165979, 1002331963, 2004663929, + + // chunk #4 + 1039, 2081, 4177, 8363, 16729, 33461, 66923, 133853, 267713, 535481, 1070981, 2141977, 4283963, 8567929, + 17135863, 34271747, 68543509, 137087021, 274174111, 548348231, 1096696463, + + // chunk #5 + 31, 67, 137, 277, 557, 1117, 2237, 4481, 8963, 17929, 35863, 71741, 143483, 286973, 573953, 1147921, + 2295859, 4591721, 9183457, 18366923, 36733847, 73467739, 146935499, 293871013, 587742049, 1175484103, + + // chunk #6 + 599, 1201, 2411, 4831, 9677, 19373, 38747, 77509, 155027, 310081, 620171, 1240361, 2480729, 4961459, + 9922933, 19845871, 39691759, 79383533, 158767069, 317534141, 635068283, 1270136683, + + // chunk #7 + 311, 631, 1277, 2557, 5119, 10243, 20507, 41017, 82037, 164089, 328213, 656429, 1312867, 2625761, 5251529, + 10503061, 21006137, 42012281, 84024581, 168049163, 336098327, 672196673, 1344393353, + + // chunk #8 + 3, 7, 17, 37, 79, 163, 331, 673, 1361, 2729, 5471, 10949, 21911, 43853, 87719, 175447, 350899, 701819, + 1403641, 2807303, 5614657, 11229331, 22458671, 44917381, 89834777, 179669557, 359339171, 718678369, + 1437356741, + + // chunk #9 + 43, 89, 179, 359, 719, 1439, 2879, 5779, 11579, 23159, 46327, 92657, 185323, 370661, 741337, 1482707, + 2965421, 5930887, 11861791, 23723597, 47447201, 94894427, 189788857, 379577741, 759155483, 1518310967, + + // chunk #10 + 379, 761, 1523, 3049, 6101, 12203, 24407, 48817, 97649, 195311, 390647, 781301, 1562611, 3125257, 6250537, + 12501169, 25002389, 50004791, 100009607, 200019221, 400038451, 800076929, 1600153859 }; + + static { // initializer + // The above prime numbers are formatted for human readability. + // To find numbers fast, we sort them once and for all. + + Arrays.sort(primeCapacities); + } + + /** + * Returns a prime number which is >= desiredCapacity and very + * close to desiredCapacity (within 11% if + * desiredCapacity >= 1000). + * + * @param desiredCapacity + * the capacity desired by the user. + * @return the capacity which should be used for a hashtable. + */ + public static final int nextPrime(int desiredCapacity) { + int i = Arrays.binarySearch(primeCapacities, desiredCapacity); + if (i < 0) { + // desired capacity not found, choose next prime greater + // than desired capacity + i = -i - 1; // remember the semantics of binarySearch... + } + return primeCapacities[i]; + } +} diff --git a/src/gnu/trove/impl/hash/TByteByteHash.java b/src/gnu/trove/impl/hash/TByteByteHash.java new file mode 100644 index 0000000..72de7d2 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteByteHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TByteByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TByteByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteByteHash(int initialCapacity, float loadFactor, byte no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TByteByteHash diff --git a/src/gnu/trove/impl/hash/TByteCharHash.java b/src/gnu/trove/impl/hash/TByteCharHash.java new file mode 100644 index 0000000..8bf34be --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteCharHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TByteCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TByteCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteCharHash(int initialCapacity, float loadFactor, byte no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TByteCharHash diff --git a/src/gnu/trove/impl/hash/TByteDoubleHash.java b/src/gnu/trove/impl/hash/TByteDoubleHash.java new file mode 100644 index 0000000..1da09ee --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteDoubleHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteDoubleHash(int initialCapacity, float loadFactor, byte no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TByteDoubleHash diff --git a/src/gnu/trove/impl/hash/TByteFloatHash.java b/src/gnu/trove/impl/hash/TByteFloatHash.java new file mode 100644 index 0000000..7f4c542 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteFloatHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteFloatHash(int initialCapacity, float loadFactor, byte no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TByteFloatHash diff --git a/src/gnu/trove/impl/hash/TByteHash.java b/src/gnu/trove/impl/hash/TByteHash.java new file mode 100644 index 0000000..71c59c9 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TByteHash instance with the default capacity and + * load factor. + */ + public TByteHash() { + super(); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteHash(int initialCapacity, float loadFactor, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte val) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TByteHash diff --git a/src/gnu/trove/impl/hash/TByteIntHash.java b/src/gnu/trove/impl/hash/TByteIntHash.java new file mode 100644 index 0000000..c5e3820 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteIntHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteIntHash(int initialCapacity, float loadFactor, byte no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TByteIntHash diff --git a/src/gnu/trove/impl/hash/TByteLongHash.java b/src/gnu/trove/impl/hash/TByteLongHash.java new file mode 100644 index 0000000..36295bd --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteLongHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteLongHash(int initialCapacity, float loadFactor, byte no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TByteLongHash diff --git a/src/gnu/trove/impl/hash/TByteShortHash.java b/src/gnu/trove/impl/hash/TByteShortHash.java new file mode 100644 index 0000000..51c1597 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteShortHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TByteShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TByteShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteShortHash(int initialCapacity, float loadFactor, byte no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TByteShortHash diff --git a/src/gnu/trove/impl/hash/TCharByteHash.java b/src/gnu/trove/impl/hash/TCharByteHash.java new file mode 100644 index 0000000..35c7524 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharByteHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TCharByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TCharByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharByteHash(int initialCapacity, float loadFactor, char no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TCharByteHash diff --git a/src/gnu/trove/impl/hash/TCharCharHash.java b/src/gnu/trove/impl/hash/TCharCharHash.java new file mode 100644 index 0000000..2674cca --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharCharHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TCharCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TCharCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharCharHash(int initialCapacity, float loadFactor, char no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TCharCharHash diff --git a/src/gnu/trove/impl/hash/TCharDoubleHash.java b/src/gnu/trove/impl/hash/TCharDoubleHash.java new file mode 100644 index 0000000..880f918 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharDoubleHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharDoubleHash(int initialCapacity, float loadFactor, char no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TCharDoubleHash diff --git a/src/gnu/trove/impl/hash/TCharFloatHash.java b/src/gnu/trove/impl/hash/TCharFloatHash.java new file mode 100644 index 0000000..e911645 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharFloatHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharFloatHash(int initialCapacity, float loadFactor, char no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TCharFloatHash diff --git a/src/gnu/trove/impl/hash/TCharHash.java b/src/gnu/trove/impl/hash/TCharHash.java new file mode 100644 index 0000000..7b1c501 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TCharHash instance with the default capacity and + * load factor. + */ + public TCharHash() { + super(); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharHash(int initialCapacity, float loadFactor, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char val) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TCharHash diff --git a/src/gnu/trove/impl/hash/TCharIntHash.java b/src/gnu/trove/impl/hash/TCharIntHash.java new file mode 100644 index 0000000..1305ba7 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharIntHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharIntHash(int initialCapacity, float loadFactor, char no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TCharIntHash diff --git a/src/gnu/trove/impl/hash/TCharLongHash.java b/src/gnu/trove/impl/hash/TCharLongHash.java new file mode 100644 index 0000000..dec1ba5 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharLongHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharLongHash(int initialCapacity, float loadFactor, char no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TCharLongHash diff --git a/src/gnu/trove/impl/hash/TCharShortHash.java b/src/gnu/trove/impl/hash/TCharShortHash.java new file mode 100644 index 0000000..29c6325 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharShortHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TCharShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TCharShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharShortHash(int initialCapacity, float loadFactor, char no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TCharShortHash diff --git a/src/gnu/trove/impl/hash/TCustomObjectHash.java b/src/gnu/trove/impl/hash/TCustomObjectHash.java new file mode 100644 index 0000000..32a4847 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCustomObjectHash.java @@ -0,0 +1,125 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.strategy.HashingStrategy; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +/** + * An open addressed hashing implementation for Object types. + * + * @author Rob Eden + * @author Eric D. Friedman + * @author Jeff Randall + * @version $Id: TObjectHash.java,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +@SuppressWarnings({ "UnusedDeclaration" }) +abstract public class TCustomObjectHash extends TObjectHash { + static final long serialVersionUID = 8766048185963756400L; + + protected HashingStrategy strategy; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TCustomObjectHash() { + } + + /** + * Creates a new TManualObjectHash instance with the default + * capacity and load factor. + */ + public TCustomObjectHash(HashingStrategy strategy) { + super(); + + this.strategy = strategy; + } + + /** + * Creates a new TManualObjectHash instance whose capacity is the + * next highest prime above initialCapacity + 1 unless that value is + * already prime. + * + * @param initialCapacity + * an int value + */ + public TCustomObjectHash(HashingStrategy strategy, int initialCapacity) { + super(initialCapacity); + + this.strategy = strategy; + } + + /** + * Creates a new TManualObjectHash instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCustomObjectHash(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(initialCapacity, loadFactor); + + this.strategy = strategy; + } + + @Override + protected int hash(Object obj) { + // noinspection unchecked + return strategy.computeHashCode((T) obj); + } + + @Override + protected boolean equals(Object one, Object two) { + // noinspection unchecked + return two != REMOVED && strategy.equals((T) one, (T) two); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + // noinspection unchecked + strategy = (HashingStrategy) in.readObject(); + } +} // TCustomObjectHash diff --git a/src/gnu/trove/impl/hash/TDoubleByteHash.java b/src/gnu/trove/impl/hash/TDoubleByteHash.java new file mode 100644 index 0000000..4b59192 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TDoubleByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TDoubleByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleByteHash(int initialCapacity, float loadFactor, double no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TDoubleByteHash diff --git a/src/gnu/trove/impl/hash/TDoubleCharHash.java b/src/gnu/trove/impl/hash/TDoubleCharHash.java new file mode 100644 index 0000000..dde1f90 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TDoubleCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TDoubleCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleCharHash(int initialCapacity, float loadFactor, double no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TDoubleCharHash diff --git a/src/gnu/trove/impl/hash/TDoubleDoubleHash.java b/src/gnu/trove/impl/hash/TDoubleDoubleHash.java new file mode 100644 index 0000000..af43a94 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleDoubleHash instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleDoubleHash instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleDoubleHash(int initialCapacity, float loadFactor, double no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TDoubleDoubleHash diff --git a/src/gnu/trove/impl/hash/TDoubleFloatHash.java b/src/gnu/trove/impl/hash/TDoubleFloatHash.java new file mode 100644 index 0000000..145dbbd --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleFloatHash(int initialCapacity, float loadFactor, double no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TDoubleFloatHash diff --git a/src/gnu/trove/impl/hash/TDoubleHash.java b/src/gnu/trove/impl/hash/TDoubleHash.java new file mode 100644 index 0000000..17cb9d2 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TDoubleHash instance with the default capacity and + * load factor. + */ + public TDoubleHash() { + super(); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleHash(int initialCapacity, float loadFactor, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double val) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TDoubleHash diff --git a/src/gnu/trove/impl/hash/TDoubleIntHash.java b/src/gnu/trove/impl/hash/TDoubleIntHash.java new file mode 100644 index 0000000..459e0ae --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleIntHash(int initialCapacity, float loadFactor, double no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TDoubleIntHash diff --git a/src/gnu/trove/impl/hash/TDoubleLongHash.java b/src/gnu/trove/impl/hash/TDoubleLongHash.java new file mode 100644 index 0000000..191b996 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleLongHash(int initialCapacity, float loadFactor, double no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TDoubleLongHash diff --git a/src/gnu/trove/impl/hash/TDoubleShortHash.java b/src/gnu/trove/impl/hash/TDoubleShortHash.java new file mode 100644 index 0000000..354a04b --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TDoubleShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TDoubleShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleShortHash(int initialCapacity, float loadFactor, double no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TDoubleShortHash diff --git a/src/gnu/trove/impl/hash/TFloatByteHash.java b/src/gnu/trove/impl/hash/TFloatByteHash.java new file mode 100644 index 0000000..aa5bc98 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TFloatByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TFloatByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatByteHash(int initialCapacity, float loadFactor, float no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TFloatByteHash diff --git a/src/gnu/trove/impl/hash/TFloatCharHash.java b/src/gnu/trove/impl/hash/TFloatCharHash.java new file mode 100644 index 0000000..f510a78 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TFloatCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TFloatCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatCharHash(int initialCapacity, float loadFactor, float no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TFloatCharHash diff --git a/src/gnu/trove/impl/hash/TFloatDoubleHash.java b/src/gnu/trove/impl/hash/TFloatDoubleHash.java new file mode 100644 index 0000000..2a66bf8 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatDoubleHash(int initialCapacity, float loadFactor, float no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TFloatDoubleHash diff --git a/src/gnu/trove/impl/hash/TFloatFloatHash.java b/src/gnu/trove/impl/hash/TFloatFloatHash.java new file mode 100644 index 0000000..6eaffee --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatFloatHash(int initialCapacity, float loadFactor, float no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TFloatFloatHash diff --git a/src/gnu/trove/impl/hash/TFloatHash.java b/src/gnu/trove/impl/hash/TFloatHash.java new file mode 100644 index 0000000..0561b88 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TFloatHash instance with the default capacity and + * load factor. + */ + public TFloatHash() { + super(); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatHash(int initialCapacity, float loadFactor, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float val) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TFloatHash diff --git a/src/gnu/trove/impl/hash/TFloatIntHash.java b/src/gnu/trove/impl/hash/TFloatIntHash.java new file mode 100644 index 0000000..e0fa7d3 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatIntHash(int initialCapacity, float loadFactor, float no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TFloatIntHash diff --git a/src/gnu/trove/impl/hash/TFloatLongHash.java b/src/gnu/trove/impl/hash/TFloatLongHash.java new file mode 100644 index 0000000..e766b89 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatLongHash(int initialCapacity, float loadFactor, float no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TFloatLongHash diff --git a/src/gnu/trove/impl/hash/TFloatShortHash.java b/src/gnu/trove/impl/hash/TFloatShortHash.java new file mode 100644 index 0000000..f49413e --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TFloatShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TFloatShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatShortHash(int initialCapacity, float loadFactor, float no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TFloatShortHash diff --git a/src/gnu/trove/impl/hash/THash.java b/src/gnu/trove/impl/hash/THash.java new file mode 100644 index 0000000..855d75b --- /dev/null +++ b/src/gnu/trove/impl/hash/THash.java @@ -0,0 +1,406 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.PrimeFinder; + +import java.io.Externalizable; +import java.io.ObjectOutput; +import java.io.IOException; +import java.io.ObjectInput; + +/** + * Base class for hashtables that use open addressing to resolve collisions. + * + * Created: Wed Nov 28 21:11:16 2001 + * + * @author Eric D. Friedman + * @author Rob Eden (auto-compaction) + * @author Jeff Randall + * + * @version $Id: THash.java,v 1.1.2.4 2010/03/02 00:55:34 robeden Exp $ + */ +abstract public class THash implements Externalizable { + @SuppressWarnings({ "UnusedDeclaration" }) + static final long serialVersionUID = -1792948471915530295L; + + /** the load above which rehashing occurs. */ + protected static final float DEFAULT_LOAD_FACTOR = Constants.DEFAULT_LOAD_FACTOR; + + /** + * the default initial capacity for the hash table. This is one less than a + * prime value because one is added to it when searching for a prime capacity to + * account for the free slot required by open addressing. Thus, the real default + * capacity is 11. + */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the current number of occupied slots in the hash. */ + protected transient int _size; + + /** the current number of free slots in the hash. */ + protected transient int _free; + + /** + * Determines how full the internal table can become before rehashing is + * required. This must be a value in the range: 0.0 < loadFactor < 1.0. The + * default value is 0.5, which is about as large as you can get in open + * addressing without hurting performance. Cf. Knuth, Volume 3., Chapter 6. + */ + protected float _loadFactor; + + /** + * The maximum number of elements allowed without allocating more space. + */ + protected int _maxSize; + + /** + * The number of removes that should be performed before an auto-compaction + * occurs. + */ + protected int _autoCompactRemovesRemaining; + + /** + * The auto-compaction factor for the table. + * + * @see #setAutoCompactionFactor + */ + protected float _autoCompactionFactor; + + /** @see #tempDisableAutoCompaction */ + protected transient boolean _autoCompactTemporaryDisable = false; + + /** + * Creates a new THash instance with the default capacity and load + * factor. + */ + public THash() { + this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); + } + + /** + * Creates a new THash instance with a prime capacity at or near + * the specified capacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public THash(int initialCapacity) { + this(initialCapacity, DEFAULT_LOAD_FACTOR); + } + + /** + * Creates a new THash instance with a prime capacity at or near + * the minimum needed to hold initialCapacity elements with load factor + * loadFactor without triggering a rehash. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public THash(int initialCapacity, float loadFactor) { + super(); + _loadFactor = loadFactor; + + // Through testing, the load factor (especially the default load factor) has + // been + // found to be a pretty good starting auto-compaction factor. + _autoCompactionFactor = loadFactor; + + setUp(HashFunctions.fastCeil(initialCapacity / loadFactor)); + } + + /** + * Tells whether this set is currently holding any elements. + * + * @return a boolean value + */ + public boolean isEmpty() { + return 0 == _size; + } + + /** + * Returns the number of distinct elements in this collection. + * + * @return an int value + */ + public int size() { + return _size; + } + + /** @return the current physical capacity of the hash table. */ + abstract public int capacity(); + + /** + * Ensure that this hashtable has sufficient capacity to hold + * desiredCapacity additional elements without + * requiring a rehash. This is a tuning method you can call + * before doing a large insert. + * + * @param desiredCapacity an int value + */ + public void ensureCapacity(int desiredCapacity) { + if (desiredCapacity > (_maxSize - size())) { + rehash(PrimeFinder.nextPrime( + Math.max(size() + 1, HashFunctions.fastCeil((desiredCapacity + size()) / _loadFactor) + 1))); + computeMaxSize(capacity()); + } + } + + /** + * Compresses the hashtable to the minimum prime size (as defined by + * PrimeFinder) that will hold all of the elements currently in the table. If + * you have done a lot of remove operations and plan to do a lot of + * queries or insertions or iteration, it is a good idea to invoke this method. + * Doing so will accomplish two things: + *

+ *

    + *
  1. You'll free memory allocated to the table but no longer needed because of + * the remove()s.
  2. + *

    + *

  3. You'll get better query/insert/iterator performance because there won't + * be any REMOVED slots to skip over when probing for indices in the + * table.
  4. + *
+ */ + public void compact() { + // need at least one free spot for open addressing + rehash(PrimeFinder.nextPrime(Math.max(_size + 1, HashFunctions.fastCeil(size() / _loadFactor) + 1))); + computeMaxSize(capacity()); + + // If auto-compaction is enabled, re-determine the compaction interval + if (_autoCompactionFactor != 0) { + computeNextAutoCompactionAmount(size()); + } + } + + /** + * The auto-compaction factor controls whether and when a table performs a + * {@link #compact} automatically after a certain number of remove operations. + * If the value is non-zero, the number of removes that need to occur for + * auto-compaction is the size of table at the time of the previous compaction + * (or the initial capacity) multiplied by this factor. + *

+ * Setting this value to zero will disable auto-compaction. + * + * @param factor + * a float that indicates the auto-compaction factor + */ + public void setAutoCompactionFactor(float factor) { + if (factor < 0) { + throw new IllegalArgumentException("Factor must be >= 0: " + factor); + } + + _autoCompactionFactor = factor; + } + + /** + * @see #setAutoCompactionFactor + * + * @return a <float that represents the auto-compaction factor. + */ + public float getAutoCompactionFactor() { + return _autoCompactionFactor; + } + + /** + * This simply calls {@link #compact compact}. It is included for symmetry with + * other collection classes. Note that the name of this method is somewhat + * misleading (which is why we prefer compact) as the load factor may + * require capacity above and beyond the size of this collection. + * + * @see #compact + */ + public final void trimToSize() { + compact(); + } + + /** + * Delete the record at index. Reduces the size of the collection by + * one. + * + * @param index + * an int value + */ + protected void removeAt(int index) { + _size--; + + // If auto-compaction is enabled, see if we need to compact + if (_autoCompactionFactor != 0) { + _autoCompactRemovesRemaining--; + + if (!_autoCompactTemporaryDisable && _autoCompactRemovesRemaining <= 0) { + // Do the compact + // NOTE: this will cause the next compaction interval to be calculated + compact(); + } + } + } + + /** Empties the collection. */ + public void clear() { + _size = 0; + _free = capacity(); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + protected int setUp(int initialCapacity) { + int capacity; + + capacity = PrimeFinder.nextPrime(initialCapacity); + computeMaxSize(capacity); + computeNextAutoCompactionAmount(initialCapacity); + + return capacity; + } + + /** + * Rehashes the set. + * + * @param newCapacity + * an int value + */ + protected abstract void rehash(int newCapacity); + + /** + * Temporarily disables auto-compaction. MUST be followed by calling + * {@link #reenableAutoCompaction}. + */ + public void tempDisableAutoCompaction() { + _autoCompactTemporaryDisable = true; + } + + /** + * Re-enable auto-compaction after it was disabled via + * {@link #tempDisableAutoCompaction()}. + * + * @param check_for_compaction + * True if compaction should be performed if needed before returning. + * If false, no compaction will be performed. + */ + public void reenableAutoCompaction(boolean check_for_compaction) { + _autoCompactTemporaryDisable = false; + + if (check_for_compaction && _autoCompactRemovesRemaining <= 0 && _autoCompactionFactor != 0) { + + // Do the compact + // NOTE: this will cause the next compaction interval to be calculated + compact(); + } + } + + /** + * Computes the values of maxSize. There will always be at least one free slot + * required. + * + * @param capacity + * an int value + */ + protected void computeMaxSize(int capacity) { + // need at least one free slot for open addressing + _maxSize = Math.min(capacity - 1, (int) (capacity * _loadFactor)); + _free = capacity - _size; // reset the free element count + } + + /** + * Computes the number of removes that need to happen before the next + * auto-compaction will occur. + * + * @param size + * an int that sets the auto-compaction limit. + */ + protected void computeNextAutoCompactionAmount(int size) { + if (_autoCompactionFactor != 0) { + // NOTE: doing the round ourselves has been found to be faster than using + // Math.round. + _autoCompactRemovesRemaining = (int) ((size * _autoCompactionFactor) + 0.5f); + } + } + + /** + * After an insert, this hook is called to adjust the size/free values of the + * set and to perform rehashing if necessary. + * + * @param usedFreeSlot + * the slot + */ + protected final void postInsertHook(boolean usedFreeSlot) { + if (usedFreeSlot) { + _free--; + } + + // rehash whenever we exhaust the available space in the table + if (++_size > _maxSize || _free == 0) { + // choose a new capacity suited to the new state of the table + // if we've grown beyond our maximum size, double capacity; + // if we've exhausted the free spots, rehash to the same capacity, + // which will free up any stale removed slots for reuse. + int newCapacity = _size > _maxSize ? PrimeFinder.nextPrime(capacity() << 1) : capacity(); + rehash(newCapacity); + computeMaxSize(capacity()); + } + } + + protected int calculateGrownCapacity() { + return capacity() << 1; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LOAD FACTOR + out.writeFloat(_loadFactor); + + // AUTO COMPACTION LOAD FACTOR + out.writeFloat(_autoCompactionFactor); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LOAD FACTOR + float old_factor = _loadFactor; + _loadFactor = in.readFloat(); + + // AUTO COMPACTION LOAD FACTOR + _autoCompactionFactor = in.readFloat(); + + // If we change the laod factor from the default, re-setup + if (old_factor != _loadFactor) { + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + } +}// THash \ No newline at end of file diff --git a/src/gnu/trove/impl/hash/THashIterator.java b/src/gnu/trove/impl/hash/THashIterator.java new file mode 100644 index 0000000..4d1812d --- /dev/null +++ b/src/gnu/trove/impl/hash/THashIterator.java @@ -0,0 +1,170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.iterator.TIterator; + +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Implements all iterator functions for the hashed object set. Subclasses may + * override objectAtIndex to vary the object returned by calls to next() (e.g. + * for values, and Map.Entry objects). + *

+ *

+ * Note that iteration is fastest if you forego the calls to hasNext in + * favor of checking the size of the structure yourself and then call next() + * that many times: + *

+ * + *

+ * Iterator i = collection.iterator();
+ * for (int size = collection.size(); size-- > 0;) {
+ * 	Object o = i.next();
+ * }
+ * 
+ *

+ *

+ * You may, of course, use the hasNext(), next() idiom too if you aren't in a + * performance critical spot. + *

+ */ +public abstract class THashIterator implements TIterator, Iterator { + + private final TObjectHash _object_hash; + + /** the data structure this iterator traverses */ + protected final THash _hash; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** + * Create an instance of THashIterator over the values of the TObjectHash + * + * @param hash + * the object + */ + protected THashIterator(TObjectHash hash) { + _hash = hash; + _expectedSize = _hash.size(); + _index = _hash.capacity(); + _object_hash = hash; + } + + /** + * Moves the iterator to the next Object and returns it. + * + * @return an Object value + * @throws ConcurrentModificationException + * if the structure was changed using a method that isn't on this + * iterator. + * @throws NoSuchElementException + * if this is called on an exhausted iterator. + */ + @Override + public V next() { + moveToNextIndex(); + return objectAtIndex(_index); + } + + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + _hash.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = _object_hash._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + + /** + * Returns the object at the specified index. Subclasses should implement this + * to return the appropriate object for the given index. + * + * @param index + * the index of the value to return. + * @return an Object value + */ + abstract protected V objectAtIndex(int index); +} // THashIterator diff --git a/src/gnu/trove/impl/hash/THashPrimitiveIterator.java b/src/gnu/trove/impl/hash/THashPrimitiveIterator.java new file mode 100644 index 0000000..bafd58c --- /dev/null +++ b/src/gnu/trove/impl/hash/THashPrimitiveIterator.java @@ -0,0 +1,139 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.iterator.TPrimitiveIterator; + +import java.util.ConcurrentModificationException; +import java.util.NoSuchElementException; + +/** + * Implements all iterator functions for the hashed object set. Subclasses may + * override objectAtIndex to vary the object returned by calls to next() (e.g. + * for values, and Map.Entry objects). + *

+ *

+ * Note that iteration is fastest if you forego the calls to hasNext in + * favor of checking the size of the structure yourself and then call next() + * that many times: + *

+ * + *

+ * Iterator i = collection.iterator();
+ * for (int size = collection.size(); size-- > 0;) {
+ * 	Object o = i.next();
+ * }
+ * 
+ *

+ *

+ * You may, of course, use the hasNext(), next() idiom too if you aren't in a + * performance critical spot. + *

+ */ +public abstract class THashPrimitiveIterator implements TPrimitiveIterator { + + /** the data structure this iterator traverses */ + protected final TPrimitiveHash _hash; + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + /** the index used for iteration. */ + protected int _index; + + /** + * Creates a TPrimitiveIterator for the specified collection. + * + * @param hash + * the TPrimitiveHash we want to iterate over. + */ + public THashPrimitiveIterator(TPrimitiveHash hash) { + _hash = hash; + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + byte[] states = _hash._states; + int i = _index; + while (i-- > 0 && (states[i] != TPrimitiveHash.FULL)) { + ; + } + return i; + } + + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + _hash.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + +} // TPrimitiveIterator \ No newline at end of file diff --git a/src/gnu/trove/impl/hash/TIntByteHash.java b/src/gnu/trove/impl/hash/TIntByteHash.java new file mode 100644 index 0000000..42a2bd5 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TIntByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TIntByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntByteHash(int initialCapacity, float loadFactor, int no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TIntByteHash diff --git a/src/gnu/trove/impl/hash/TIntCharHash.java b/src/gnu/trove/impl/hash/TIntCharHash.java new file mode 100644 index 0000000..de790ed --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TIntCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TIntCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntCharHash(int initialCapacity, float loadFactor, int no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TIntCharHash diff --git a/src/gnu/trove/impl/hash/TIntDoubleHash.java b/src/gnu/trove/impl/hash/TIntDoubleHash.java new file mode 100644 index 0000000..75c982a --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntDoubleHash(int initialCapacity, float loadFactor, int no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TIntDoubleHash diff --git a/src/gnu/trove/impl/hash/TIntFloatHash.java b/src/gnu/trove/impl/hash/TIntFloatHash.java new file mode 100644 index 0000000..e8f79fb --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntFloatHash(int initialCapacity, float loadFactor, int no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TIntFloatHash diff --git a/src/gnu/trove/impl/hash/TIntHash.java b/src/gnu/trove/impl/hash/TIntHash.java new file mode 100644 index 0000000..bb95028 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TIntHash instance with the default capacity and + * load factor. + */ + public TIntHash() { + super(); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntHash(int initialCapacity, float loadFactor, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int val) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TIntHash diff --git a/src/gnu/trove/impl/hash/TIntIntHash.java b/src/gnu/trove/impl/hash/TIntIntHash.java new file mode 100644 index 0000000..a7f284f --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntIntHash(int initialCapacity, float loadFactor, int no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TIntIntHash diff --git a/src/gnu/trove/impl/hash/TIntLongHash.java b/src/gnu/trove/impl/hash/TIntLongHash.java new file mode 100644 index 0000000..b9b28c0 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntLongHash(int initialCapacity, float loadFactor, int no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TIntLongHash diff --git a/src/gnu/trove/impl/hash/TIntShortHash.java b/src/gnu/trove/impl/hash/TIntShortHash.java new file mode 100644 index 0000000..3dfb674 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TIntShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TIntShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntShortHash(int initialCapacity, float loadFactor, int no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TIntShortHash diff --git a/src/gnu/trove/impl/hash/TLongByteHash.java b/src/gnu/trove/impl/hash/TLongByteHash.java new file mode 100644 index 0000000..6ee089a --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TLongByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TLongByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongByteHash(int initialCapacity, float loadFactor, long no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TLongByteHash diff --git a/src/gnu/trove/impl/hash/TLongCharHash.java b/src/gnu/trove/impl/hash/TLongCharHash.java new file mode 100644 index 0000000..8da7eeb --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TLongCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TLongCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongCharHash(int initialCapacity, float loadFactor, long no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TLongCharHash diff --git a/src/gnu/trove/impl/hash/TLongDoubleHash.java b/src/gnu/trove/impl/hash/TLongDoubleHash.java new file mode 100644 index 0000000..2294f65 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongDoubleHash(int initialCapacity, float loadFactor, long no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TLongDoubleHash diff --git a/src/gnu/trove/impl/hash/TLongFloatHash.java b/src/gnu/trove/impl/hash/TLongFloatHash.java new file mode 100644 index 0000000..fd47b15 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongFloatHash(int initialCapacity, float loadFactor, long no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TLongFloatHash diff --git a/src/gnu/trove/impl/hash/TLongHash.java b/src/gnu/trove/impl/hash/TLongHash.java new file mode 100644 index 0000000..f3eee49 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TLongHash instance with the default capacity and + * load factor. + */ + public TLongHash() { + super(); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongHash(int initialCapacity, float loadFactor, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long val) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TLongHash diff --git a/src/gnu/trove/impl/hash/TLongIntHash.java b/src/gnu/trove/impl/hash/TLongIntHash.java new file mode 100644 index 0000000..4ccb921 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongIntHash(int initialCapacity, float loadFactor, long no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TLongIntHash diff --git a/src/gnu/trove/impl/hash/TLongLongHash.java b/src/gnu/trove/impl/hash/TLongLongHash.java new file mode 100644 index 0000000..0ce5034 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongLongHash(int initialCapacity, float loadFactor, long no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TLongLongHash diff --git a/src/gnu/trove/impl/hash/TLongShortHash.java b/src/gnu/trove/impl/hash/TLongShortHash.java new file mode 100644 index 0000000..547bb85 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TLongShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TLongShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongShortHash(int initialCapacity, float loadFactor, long no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TLongShortHash diff --git a/src/gnu/trove/impl/hash/TObjectHash.java b/src/gnu/trove/impl/hash/TObjectHash.java new file mode 100644 index 0000000..3235d4f --- /dev/null +++ b/src/gnu/trove/impl/hash/TObjectHash.java @@ -0,0 +1,630 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TObjectProcedure; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * An open addressed hashing implementation for Object types. + *

+ * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: TObjectHash.java,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TObjectHash extends THash { + + @SuppressWarnings({ "UnusedDeclaration" }) + static final long serialVersionUID = -3461112548087185871L; + + /** + * the set of Objects + */ + public transient Object[] _set; + + public static final Object REMOVED = new Object(), FREE = new Object(); + + /** + * Indicates whether the last insertKey() call used a FREE slot. This field + * should be inspected right after call insertKey() + */ + protected boolean consumeFreeSlot; + + /** + * Creates a new TObjectHash instance with the default capacity and + * load factor. + */ + public TObjectHash() { + super(); + } + + /** + * Creates a new TObjectHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TObjectHash(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TObjectHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TObjectHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + @Override + public int capacity() { + return _set.length; + } + + @Override + protected void removeAt(int index) { + _set[index] = REMOVED; + super.removeAt(index); + } + + /** + * initializes the Object set of this hash table. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new Object[capacity]; + Arrays.fill(_set, FREE); + return capacity; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @SuppressWarnings({ "unchecked" }) + public boolean forEach(TObjectProcedure procedure) { + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && !procedure.execute((T) set[i])) { + return false; + } + } + return true; + } + + /** + * Searches the set for obj + * + * @param obj + * an Object value + * @return a boolean value + */ + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object obj) { + return index(obj) >= 0; + } + + /** + * Locates the index of obj. + * + * @param obj + * an Object value + * @return the index of obj or -1 if it isn't in the set. + */ + protected int index(Object obj) { + if (obj == null) + return indexForNull(); + + // From here on we know obj to be non-null + final int hash = hash(obj) & 0x7fffffff; + int index = hash % _set.length; + Object cur = _set[index]; + + if (cur == FREE) { + return -1; + } + + if (cur == obj || equals(obj, cur)) { + return index; + } + + return indexRehashed(obj, index, hash, cur); + } + + /** + * Locates the index of non-null obj. + * + * @param obj + * target key, know to be non-null + * @param index + * we start from + * @param hash + * @param cur + * @return + */ + private int indexRehashed(Object obj, int index, int hash, Object cur) { + final Object[] set = _set; + final int length = set.length; + + // NOTE: here it has to be REMOVED or FULL (some user-given value) + // see Knuth, p. 529 + int probe = 1 + (hash % (length - 2)); + + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + cur = set[index]; + // + if (cur == FREE) + return -1; + + // + if ((cur == obj || equals(obj, cur))) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index null. + *

+ * null specific loop exploiting several properties to simplify the iteration + * logic - the null value hashes to 0 we so we can iterate from the beginning. - + * the probe value is 1 for this case - object identity can be used to match + * this case + *

+ * --> this result a simpler loop + * + * @return + */ + private int indexForNull() { + int index = 0; + for (Object o : _set) { + if (o == null) + return index; + + if (o == FREE) + return -1; + + index++; + } + + return -1; + } + + /** + * Alias introduced to avoid breaking the API. The new method name insertKey() + * reflects the changes made to the logic. + * + * @param obj + * @return + * @deprecated use {@link #insertKey} instead + */ + @Deprecated + protected int insertionIndex(T obj) { + return insertKey(obj); + } + + /** + * Locates the index at which key can be inserted. if there is already + * a value equal()ing key in the set, returns that value's index as + * -index - 1. + *

+ * If a slot is found the value is inserted. When a FREE slot is used the + * consumeFreeSlot field is set to true. This field should be used in the method + * invoking insertKey() to pass to postInsertHook() + * + * @param key + * an Object value + * @return the index of a FREE slot at which key can be inserted or, if key is + * already stored in the hash, the negative value of that index, minus + * 1: -index -1. + */ + protected int insertKey(T key) { + consumeFreeSlot = false; + + if (key == null) + return insertKeyForNull(); + + final int hash = hash(key) & 0x7fffffff; + int index = hash % _set.length; + Object cur = _set[index]; + + if (cur == FREE) { + consumeFreeSlot = true; + _set[index] = key; // insert value + return index; // empty, all done + } + + if (cur == key || equals(key, cur)) { + return -index - 1; // already stored + } + + return insertKeyRehash(key, index, hash, cur); + } + + /** + * Looks for a slot using double hashing for a non-null key values and inserts + * the value in the slot + * + * @param key + * non-null key value + * @param index + * natural index + * @param hash + * @param cur + * value of first matched slot + * @return + */ + private int insertKeyRehash(T key, int index, int hash, Object cur) { + final Object[] set = _set; + final int length = set.length; + // already FULL or REMOVED, must probe + // compute the double hash + final int probe = 1 + (hash % (length - 2)); + + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (cur == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + cur = set[index]; + + // A FREE slot stops the search + if (cur == FREE) { + if (firstRemoved != -1) { + _set[firstRemoved] = key; + return firstRemoved; + } else { + consumeFreeSlot = true; + _set[index] = key; // insert value + return index; + } + } + + if (cur == key || equals(key, cur)) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + _set[firstRemoved] = key; + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + /** + * Looks for a slot using double hashing for a null key value and inserts the + * value. + *

+ * null specific loop exploiting several properties to simplify the iteration + * logic - the null value hashes to 0 we so we can iterate from the beginning. - + * the probe value is 1 for this case - object identity can be used to match + * this case + * + * @return + */ + private int insertKeyForNull() { + int index = 0; + int firstRemoved = -1; + + // Look for a slot containing the 'null' value as key + for (Object o : _set) { + // Locate first removed + if (o == REMOVED && firstRemoved == -1) + firstRemoved = index; + + if (o == FREE) { + if (firstRemoved != -1) { + _set[firstRemoved] = null; + return firstRemoved; + } else { + consumeFreeSlot = true; + _set[index] = null; // insert value + return index; + } + } + + if (o == null) { + return -index - 1; + } + + index++; + } + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + _set[firstRemoved] = null; + return firstRemoved; + } + + // We scanned the entire key set and found nothing, is set full? + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("Could not find insertion index for null key. Key set full!?!!"); + } + + /** + * Convenience methods for subclasses to use in throwing exceptions about badly + * behaved user objects employed as keys. We have to throw an + * IllegalArgumentException with a rather verbose message telling the user that + * they need to fix their object implementation to conform to the general + * contract for java.lang.Object. + * + * + * @param o1 + * the first of the equal elements with unequal hash codes. + * @param o2 + * the second of the equal elements with unequal hash codes. + * @throws IllegalArgumentException + * the whole point of this method. + */ + protected final void throwObjectContractViolation(Object o1, Object o2) throws IllegalArgumentException { + throw buildObjectContractViolation(o1, o2, ""); + } + + /** + * Convenience methods for subclasses to use in throwing exceptions about badly + * behaved user objects employed as keys. We have to throw an + * IllegalArgumentException with a rather verbose message telling the user that + * they need to fix their object implementation to conform to the general + * contract for java.lang.Object. + * + * + * @param o1 + * the first of the equal elements with unequal hash codes. + * @param o2 + * the second of the equal elements with unequal hash codes. + * @param size + * @param oldSize + * @param oldKeys + * @throws IllegalArgumentException + * the whole point of this method. + */ + protected final void throwObjectContractViolation(Object o1, Object o2, int size, int oldSize, Object[] oldKeys) + throws IllegalArgumentException { + String extra = dumpExtraInfo(o1, o2, size(), oldSize, oldKeys); + + throw buildObjectContractViolation(o1, o2, extra); + } + + /** + * Convenience methods for subclasses to use in throwing exceptions about badly + * behaved user objects employed as keys. We have to throw an + * IllegalArgumentException with a rather verbose message telling the user that + * they need to fix their object implementation to conform to the general + * contract for java.lang.Object. + * + * + * @param o1 + * the first of the equal elements with unequal hash codes. + * @param o2 + * the second of the equal elements with unequal hash codes. + * @throws IllegalArgumentException + * the whole point of this method. + */ + protected final IllegalArgumentException buildObjectContractViolation(Object o1, Object o2, String extra) { + return new IllegalArgumentException("Equal objects must have equal hashcodes. " + + "During rehashing, Trove discovered that the following two objects claim " + + "to be equal (as in java.lang.Object.equals()) but their hashCodes (or " + + "those calculated by your TObjectHashingStrategy) are not equal." + + "This violates the general contract of java.lang.Object.hashCode(). See " + + "bullet point two in that method's documentation. object #1 =" + objectInfo(o1) + "; object #2 =" + + objectInfo(o2) + "\n" + extra); + } + + protected boolean equals(Object notnull, Object two) { + if (two == null || two == REMOVED) + return false; + + return notnull.equals(two); + } + + protected int hash(Object notnull) { + return notnull.hashCode(); + } + + protected static String reportPotentialConcurrentMod(int newSize, int oldSize) { + // Note that we would not be able to detect concurrent paired of put()-remove() + // operations with this simple check + if (newSize != oldSize) + return "[Warning] apparent concurrent modification of the key set. " + + "Size before and after rehash() do not match " + oldSize + " vs " + newSize; + + return ""; + } + + /** + * + * @param newVal + * the key being inserted + * @param oldVal + * the key already stored at that position + * @param currentSize + * size of the key set during rehashing + * @param oldSize + * size of the key set before rehashing + * @param oldKeys + * the old key set + */ + protected String dumpExtraInfo(Object newVal, Object oldVal, int currentSize, int oldSize, Object[] oldKeys) { + StringBuilder b = new StringBuilder(); + // + b.append(dumpKeyTypes(newVal, oldVal)); + + b.append(reportPotentialConcurrentMod(currentSize, oldSize)); + b.append(detectKeyLoss(oldKeys, oldSize)); + + // Is de same object already present? Double insert? + if (newVal == oldVal) { + b.append("Inserting same object twice, rehashing bug. Object= ").append(oldVal); + } + + return b.toString(); + } + + /** + * Detect inconsistent hashCode() and/or equals() methods + * + * @param keys + * @param oldSize + * @return + */ + private static String detectKeyLoss(Object[] keys, int oldSize) { + StringBuilder buf = new StringBuilder(); + Set k = makeKeySet(keys); + if (k.size() != oldSize) { + buf.append("\nhashCode() and/or equals() have inconsistent implementation"); + buf.append("\nKey set lost entries, now got ").append(k.size()).append(" instead of ").append(oldSize); + buf.append(". This can manifest itself as an apparent duplicate key."); + } + + return buf.toString(); + } + + private static Set makeKeySet(Object[] keys) { + Set types = new HashSet(); + for (Object o : keys) { + if (o != FREE && o != REMOVED) { + types.add(o); + } + } + + return types; + } + + private static String equalsSymmetryInfo(Object a, Object b) { + StringBuilder buf = new StringBuilder(); + if (a == b) { + return "a == b"; + } + + if (a.getClass() != b.getClass()) { + buf.append("Class of objects differ a=").append(a.getClass()).append(" vs b=").append(b.getClass()); + + boolean aEb = a.equals(b); + boolean bEa = b.equals(a); + if (aEb != bEa) { + buf.append("\nequals() of a or b object are asymmetric"); + buf.append("\na.equals(b) =").append(aEb); + buf.append("\nb.equals(a) =").append(bEa); + } + } + + return buf.toString(); + } + + protected static String objectInfo(Object o) { + return (o == null ? "class null" : o.getClass()) + " id= " + System.identityHashCode(o) + " hashCode= " + + (o == null ? 0 : o.hashCode()) + " toString= " + String.valueOf(o); + } + + private String dumpKeyTypes(Object newVal, Object oldVal) { + StringBuilder buf = new StringBuilder(); + Set> types = new HashSet>(); + for (Object o : _set) { + if (o != FREE && o != REMOVED) { + if (o != null) + types.add(o.getClass()); + else + types.add(null); + } + } + + if (types.size() > 1) { + buf.append("\nMore than one type used for keys. Watch out for asymmetric equals(). " + + "Read about the 'Liskov substitution principle' and the implications for equals() in java."); + + buf.append("\nKey types: ").append(types); + buf.append(equalsSymmetryInfo(newVal, oldVal)); + } + + return buf.toString(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + } +} // TObjectHash diff --git a/src/gnu/trove/impl/hash/TPrimitiveHash.java b/src/gnu/trove/impl/hash/TPrimitiveHash.java new file mode 100644 index 0000000..f62f750 --- /dev/null +++ b/src/gnu/trove/impl/hash/TPrimitiveHash.java @@ -0,0 +1,134 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.impl.HashFunctions; + +/** + * The base class for hashtables of primitive values. Since there is no notion + * of object equality for primitives, it isn't possible to use a `REMOVED' + * object to track deletions in an open-addressed table. So, we have to resort + * to using a parallel `bookkeeping' array of bytes, in which flags can be set + * to indicate that a particular slot in the hash table is FREE, FULL, or + * REMOVED. + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: TPrimitiveHash.java,v 1.1.2.6 2010/03/01 23:39:07 robeden Exp $ + */ +abstract public class TPrimitiveHash extends THash { + @SuppressWarnings({ "UnusedDeclaration" }) + static final long serialVersionUID = 1L; + + /** + * flags indicating whether each position in the hash is FREE, FULL, or REMOVED + */ + public transient byte[] _states; + + /* constants used for state flags */ + + /** flag indicating that a slot in the hashtable is available */ + public static final byte FREE = 0; + + /** flag indicating that a slot in the hashtable is occupied */ + public static final byte FULL = 1; + + /** + * flag indicating that the value of a slot in the hashtable was deleted + */ + public static final byte REMOVED = 2; + + /** + * Creates a new THash instance with the default capacity and load + * factor. + */ + public TPrimitiveHash() { + super(); + } + + /** + * Creates a new TPrimitiveHash instance with a prime capacity at + * or near the specified capacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TPrimitiveHash(int initialCapacity) { + this(initialCapacity, DEFAULT_LOAD_FACTOR); + } + + /** + * Creates a new TPrimitiveHash instance with a prime capacity at + * or near the minimum needed to hold + * initialCapacity elements with load factor + * loadFactor without triggering a rehash. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TPrimitiveHash(int initialCapacity, float loadFactor) { + super(); + initialCapacity = Math.max(1, initialCapacity); + _loadFactor = loadFactor; + setUp(HashFunctions.fastCeil(initialCapacity / loadFactor)); + } + + /** + * Returns the capacity of the hash table. This is the true physical capacity, + * without adjusting for the load factor. + * + * @return the physical capacity of the hash table. + */ + @Override + public int capacity() { + return _states.length; + } + + /** + * Delete the record at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _states[index] = REMOVED; + super.removeAt(index); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _states = new byte[capacity]; + return capacity; + } +} // TPrimitiveHash \ No newline at end of file diff --git a/src/gnu/trove/impl/hash/TShortByteHash.java b/src/gnu/trove/impl/hash/TShortByteHash.java new file mode 100644 index 0000000..c45b678 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortByteHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TShortByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TShortByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortByteHash(int initialCapacity, float loadFactor, short no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TShortByteHash diff --git a/src/gnu/trove/impl/hash/TShortCharHash.java b/src/gnu/trove/impl/hash/TShortCharHash.java new file mode 100644 index 0000000..1758503 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortCharHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TShortCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TShortCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortCharHash(int initialCapacity, float loadFactor, short no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TShortCharHash diff --git a/src/gnu/trove/impl/hash/TShortDoubleHash.java b/src/gnu/trove/impl/hash/TShortDoubleHash.java new file mode 100644 index 0000000..1a30bf8 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortDoubleHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortDoubleHash(int initialCapacity, float loadFactor, short no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TShortDoubleHash diff --git a/src/gnu/trove/impl/hash/TShortFloatHash.java b/src/gnu/trove/impl/hash/TShortFloatHash.java new file mode 100644 index 0000000..745bb22 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortFloatHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortFloatHash(int initialCapacity, float loadFactor, short no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TShortFloatHash diff --git a/src/gnu/trove/impl/hash/TShortHash.java b/src/gnu/trove/impl/hash/TShortHash.java new file mode 100644 index 0000000..850e863 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TShortHash instance with the default capacity and + * load factor. + */ + public TShortHash() { + super(); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortHash(int initialCapacity, float loadFactor, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short val) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TShortHash diff --git a/src/gnu/trove/impl/hash/TShortIntHash.java b/src/gnu/trove/impl/hash/TShortIntHash.java new file mode 100644 index 0000000..58fa16e --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortIntHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortIntHash(int initialCapacity, float loadFactor, short no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TShortIntHash diff --git a/src/gnu/trove/impl/hash/TShortLongHash.java b/src/gnu/trove/impl/hash/TShortLongHash.java new file mode 100644 index 0000000..4197503 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortLongHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortLongHash(int initialCapacity, float loadFactor, short no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TShortLongHash diff --git a/src/gnu/trove/impl/hash/TShortShortHash.java b/src/gnu/trove/impl/hash/TShortShortHash.java new file mode 100644 index 0000000..d289278 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortShortHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TShortShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TShortShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortShortHash(int initialCapacity, float loadFactor, short no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TShortShortHash diff --git a/src/gnu/trove/impl/package.html b/src/gnu/trove/impl/package.html new file mode 100644 index 0000000..c803363 --- /dev/null +++ b/src/gnu/trove/impl/package.html @@ -0,0 +1,24 @@ + + +This package (and its sub-packages) contain internal implementations used in Trove. These +classes should not be accessed directly (treat them like com.sun +classes. + \ No newline at end of file diff --git a/src/gnu/trove/impl/sync/SynchronizedCollection.java b/src/gnu/trove/impl/sync/SynchronizedCollection.java new file mode 100644 index 0000000..9f6c566 --- /dev/null +++ b/src/gnu/trove/impl/sync/SynchronizedCollection.java @@ -0,0 +1,143 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Collection; +import java.util.Iterator; + +/** + * + */ +class SynchronizedCollection implements Collection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final Collection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + SynchronizedCollection(Collection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(Object o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public Object[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + @SuppressWarnings({ "SuspiciousToArrayCall" }) + public T[] toArray(T[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public Iterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(E e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(Object o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} \ No newline at end of file diff --git a/src/gnu/trove/impl/sync/SynchronizedSet.java b/src/gnu/trove/impl/sync/SynchronizedSet.java new file mode 100644 index 0000000..e35757e --- /dev/null +++ b/src/gnu/trove/impl/sync/SynchronizedSet.java @@ -0,0 +1,46 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +import java.util.Set; + +/** + * Local implementation of SynchronizedSet so we can set the mutex explicitly. + */ +class SynchronizedSet extends SynchronizedCollection implements Set { + private static final long serialVersionUID = 487447009682186044L; + + SynchronizedSet(Set s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} \ No newline at end of file diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteByteMap.java new file mode 100644 index 0000000..4e59d10 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteByteMap implements TByteByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteByteMap(TByteByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteByteMap(TByteByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(byte key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(byte key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteCharMap.java new file mode 100644 index 0000000..df37c9d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteCharMap implements TByteCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteCharMap(TByteCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteCharMap(TByteCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(byte key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(byte key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteCollection.java b/src/gnu/trove/impl/sync/TSynchronizedByteCollection.java new file mode 100644 index 0000000..f840e64 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteCollection implements TByteCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TByteCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteCollection(TByteCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedByteCollection(TByteCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(byte o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public byte[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public byte[] toArray(byte[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TByteIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(byte e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(byte o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TByteCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(byte[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TByteCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(byte[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TByteCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(byte[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TByteCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(byte[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public byte getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TByteProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteDoubleMap.java new file mode 100644 index 0000000..f4884a9 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteDoubleMap implements TByteDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteDoubleMap(TByteDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteDoubleMap(TByteDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(byte key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(byte key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteFloatMap.java new file mode 100644 index 0000000..11c0538 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteFloatMap implements TByteFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteFloatMap(TByteFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteFloatMap(TByteFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(byte key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(byte key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteIntMap.java new file mode 100644 index 0000000..12153e3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteIntMap implements TByteIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteIntMap(TByteIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteIntMap(TByteIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(byte key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(byte key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteList.java b/src/gnu/trove/impl/sync/TSynchronizedByteList.java new file mode 100644 index 0000000..9f42207 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedByteList extends TSynchronizedByteCollection implements TByteList { + + static final long serialVersionUID = -7754090372962971524L; + + final TByteList list; + + public TSynchronizedByteList(TByteList list) { + super(list); + this.list = list; + } + + public TSynchronizedByteList(TByteList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public byte get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public byte set(int index, byte element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, byte[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public byte replace(int offset, byte val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public byte removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(byte[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(byte[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, byte value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, byte[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(byte o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(byte o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListByteIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListByteIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedByteList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public byte[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, byte value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, byte value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(byte val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, byte val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(byte value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TByteList grep(TByteProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TByteList inverseGrep(TByteProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public byte max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public byte min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public byte sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TByteProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessByteList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteLongMap.java new file mode 100644 index 0000000..8c15c7b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteLongMap implements TByteLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteLongMap(TByteLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteLongMap(TByteLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(byte key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(byte key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteObjectMap.java new file mode 100644 index 0000000..d2b3b78 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteObjectMap implements TByteObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteObjectMap(TByteObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteObjectMap(TByteObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(byte key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient Collection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(byte key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteSet.java b/src/gnu/trove/impl/sync/TSynchronizedByteSet.java new file mode 100644 index 0000000..4c60583 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedByteSet extends TSynchronizedByteCollection implements TByteSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedByteSet(TByteSet s) { + super(s); + } + + public TSynchronizedByteSet(TByteSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteShortMap.java new file mode 100644 index 0000000..c57146d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteShortMap implements TByteShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteShortMap(TByteShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteShortMap(TByteShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(byte key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(byte key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharByteMap.java new file mode 100644 index 0000000..3740110 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharByteMap implements TCharByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharByteMap(TCharByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharByteMap(TCharByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(char key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(char key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharCharMap.java new file mode 100644 index 0000000..07d2746 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharCharMap implements TCharCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharCharMap(TCharCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharCharMap(TCharCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(char key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(char key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(char key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharCollection.java b/src/gnu/trove/impl/sync/TSynchronizedCharCollection.java new file mode 100644 index 0000000..63840e9 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharCollection implements TCharCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TCharCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharCollection(TCharCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedCharCollection(TCharCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(char o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public char[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public char[] toArray(char[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TCharIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(char e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(char o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TCharCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(char[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TCharCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(char[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TCharCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(char[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TCharCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(char[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public char getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TCharProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharDoubleMap.java new file mode 100644 index 0000000..59dad75 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharDoubleMap implements TCharDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharDoubleMap(TCharDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharDoubleMap(TCharDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(char key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(char key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(char key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharFloatMap.java new file mode 100644 index 0000000..55d2ca3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharFloatMap implements TCharFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharFloatMap(TCharFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharFloatMap(TCharFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(char key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(char key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(char key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharIntMap.java new file mode 100644 index 0000000..42a591d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharIntMap implements TCharIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharIntMap(TCharIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharIntMap(TCharIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(char key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(char key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(char key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharList.java b/src/gnu/trove/impl/sync/TSynchronizedCharList.java new file mode 100644 index 0000000..19620f2 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedCharList extends TSynchronizedCharCollection implements TCharList { + + static final long serialVersionUID = -7754090372962971524L; + + final TCharList list; + + public TSynchronizedCharList(TCharList list) { + super(list); + this.list = list; + } + + public TSynchronizedCharList(TCharList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public char get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public char set(int index, char element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, char[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, char[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public char replace(int offset, char val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public char removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(char[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(char[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, char value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, char[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(char o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(char o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListCharIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListCharIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedCharList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public char[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public char[] toArray(char[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, char value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, char value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(char val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, char val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(char value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TCharList grep(TCharProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TCharList inverseGrep(TCharProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public char max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public char min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public char sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TCharProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessCharList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharLongMap.java new file mode 100644 index 0000000..9ba7a08 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharLongMap implements TCharLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharLongMap(TCharLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharLongMap(TCharLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(char key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(char key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(char key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharObjectMap.java new file mode 100644 index 0000000..0cbacc8 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharObjectMap implements TCharObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharObjectMap(TCharObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharObjectMap(TCharObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(char key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient Collection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(char key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharSet.java b/src/gnu/trove/impl/sync/TSynchronizedCharSet.java new file mode 100644 index 0000000..de57785 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedCharSet extends TSynchronizedCharCollection implements TCharSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedCharSet(TCharSet s) { + super(s); + } + + public TSynchronizedCharSet(TCharSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharShortMap.java new file mode 100644 index 0000000..2b5b4df --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharShortMap implements TCharShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharShortMap(TCharShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharShortMap(TCharShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(char key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(char key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(char key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleByteMap.java new file mode 100644 index 0000000..01684a8 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleByteMap implements TDoubleByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleByteMap(TDoubleByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleByteMap(TDoubleByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(double key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(double key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleCharMap.java new file mode 100644 index 0000000..9428de0 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleCharMap implements TDoubleCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleCharMap(TDoubleCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleCharMap(TDoubleCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(double key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(double key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(double key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleCollection.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleCollection.java new file mode 100644 index 0000000..44577c0 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleCollection implements TDoubleCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TDoubleCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleCollection(TDoubleCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedDoubleCollection(TDoubleCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(double o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public double[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public double[] toArray(double[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TDoubleIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(double e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(double o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(double[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(double[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(double[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(double[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public double getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TDoubleProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleDoubleMap.java new file mode 100644 index 0000000..b7aef8e --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleDoubleMap implements TDoubleDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleDoubleMap(TDoubleDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleDoubleMap(TDoubleDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(double key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(double key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(double key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleFloatMap.java new file mode 100644 index 0000000..ac423dc --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleFloatMap implements TDoubleFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleFloatMap(TDoubleFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleFloatMap(TDoubleFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(double key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(double key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(double key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleIntMap.java new file mode 100644 index 0000000..63953e8 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleIntMap implements TDoubleIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleIntMap(TDoubleIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleIntMap(TDoubleIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(double key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(double key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(double key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleList.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleList.java new file mode 100644 index 0000000..4590076 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedDoubleList extends TSynchronizedDoubleCollection implements TDoubleList { + + static final long serialVersionUID = -7754090372962971524L; + + final TDoubleList list; + + public TSynchronizedDoubleList(TDoubleList list) { + super(list); + this.list = list; + } + + public TSynchronizedDoubleList(TDoubleList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public double get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public double set(int index, double element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, double[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, double[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public double replace(int offset, double val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public double removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(double[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(double[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, double value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, double[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(double o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(double o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListDoubleIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListDoubleIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedDoubleList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public double[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public double[] toArray(double[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, double value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, double value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(double val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, double val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(double value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TDoubleList grep(TDoubleProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public double max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public double min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public double sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessDoubleList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleLongMap.java new file mode 100644 index 0000000..938aec7 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleLongMap implements TDoubleLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleLongMap(TDoubleLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleLongMap(TDoubleLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(double key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(double key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(double key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleObjectMap.java new file mode 100644 index 0000000..2af20eb --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleObjectMap implements TDoubleObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleObjectMap(TDoubleObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleObjectMap(TDoubleObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(double key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient Collection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(double key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleSet.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleSet.java new file mode 100644 index 0000000..c8c5834 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedDoubleSet extends TSynchronizedDoubleCollection implements TDoubleSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedDoubleSet(TDoubleSet s) { + super(s); + } + + public TSynchronizedDoubleSet(TDoubleSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleShortMap.java new file mode 100644 index 0000000..32984e1 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleShortMap implements TDoubleShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleShortMap(TDoubleShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleShortMap(TDoubleShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(double key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(double key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(double key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatByteMap.java new file mode 100644 index 0000000..d75013c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatByteMap implements TFloatByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatByteMap(TFloatByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatByteMap(TFloatByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(float key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(float key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatCharMap.java new file mode 100644 index 0000000..c7f8c4c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatCharMap implements TFloatCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatCharMap(TFloatCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatCharMap(TFloatCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(float key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(float key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(float key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatCollection.java b/src/gnu/trove/impl/sync/TSynchronizedFloatCollection.java new file mode 100644 index 0000000..cbf6223 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatCollection implements TFloatCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TFloatCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatCollection(TFloatCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedFloatCollection(TFloatCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(float o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public float[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public float[] toArray(float[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TFloatIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(float e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(float o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TFloatCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(float[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TFloatCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(float[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TFloatCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(float[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TFloatCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(float[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public float getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TFloatProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatDoubleMap.java new file mode 100644 index 0000000..2ef040d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatDoubleMap implements TFloatDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatDoubleMap(TFloatDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatDoubleMap(TFloatDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(float key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(float key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(float key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatFloatMap.java new file mode 100644 index 0000000..ee88c78 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatFloatMap implements TFloatFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatFloatMap(TFloatFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatFloatMap(TFloatFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(float key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(float key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(float key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatIntMap.java new file mode 100644 index 0000000..3b13685 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatIntMap implements TFloatIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatIntMap(TFloatIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatIntMap(TFloatIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(float key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(float key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(float key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatList.java b/src/gnu/trove/impl/sync/TSynchronizedFloatList.java new file mode 100644 index 0000000..2126b72 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedFloatList extends TSynchronizedFloatCollection implements TFloatList { + + static final long serialVersionUID = -7754090372962971524L; + + final TFloatList list; + + public TSynchronizedFloatList(TFloatList list) { + super(list); + this.list = list; + } + + public TSynchronizedFloatList(TFloatList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public float get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public float set(int index, float element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, float[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, float[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public float replace(int offset, float val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public float removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(float[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(float[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, float value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, float[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(float o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(float o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListFloatIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListFloatIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedFloatList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public float[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public float[] toArray(float[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, float value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, float value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(float val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, float val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(float value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TFloatList grep(TFloatProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public float max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public float min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public float sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessFloatList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatLongMap.java new file mode 100644 index 0000000..4c2dea0 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatLongMap implements TFloatLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatLongMap(TFloatLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatLongMap(TFloatLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(float key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(float key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(float key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatObjectMap.java new file mode 100644 index 0000000..50cf76b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatObjectMap implements TFloatObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatObjectMap(TFloatObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatObjectMap(TFloatObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(float key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient Collection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(float key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatSet.java b/src/gnu/trove/impl/sync/TSynchronizedFloatSet.java new file mode 100644 index 0000000..156230f --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedFloatSet extends TSynchronizedFloatCollection implements TFloatSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedFloatSet(TFloatSet s) { + super(s); + } + + public TSynchronizedFloatSet(TFloatSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatShortMap.java new file mode 100644 index 0000000..2f75a15 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatShortMap implements TFloatShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatShortMap(TFloatShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatShortMap(TFloatShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(float key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(float key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(float key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntByteMap.java new file mode 100644 index 0000000..10803a5 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntByteMap implements TIntByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntByteMap(TIntByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntByteMap(TIntByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(int key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(int key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntCharMap.java new file mode 100644 index 0000000..58bb763 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntCharMap implements TIntCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntCharMap(TIntCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntCharMap(TIntCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(int key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(int key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(int key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntCollection.java b/src/gnu/trove/impl/sync/TSynchronizedIntCollection.java new file mode 100644 index 0000000..b23bd7b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntCollection implements TIntCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TIntCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntCollection(TIntCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedIntCollection(TIntCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(int o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public int[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public int[] toArray(int[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TIntIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(int e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(int o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TIntCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(int[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TIntCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(int[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TIntCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(int[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TIntCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(int[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public int getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TIntProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntDoubleMap.java new file mode 100644 index 0000000..1a83b94 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntDoubleMap implements TIntDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntDoubleMap(TIntDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntDoubleMap(TIntDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(int key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(int key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(int key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntFloatMap.java new file mode 100644 index 0000000..ab90333 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntFloatMap implements TIntFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntFloatMap(TIntFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntFloatMap(TIntFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(int key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(int key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(int key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntIntMap.java new file mode 100644 index 0000000..1632c0b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntIntMap implements TIntIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntIntMap(TIntIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntIntMap(TIntIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(int key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(int key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(int key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntList.java b/src/gnu/trove/impl/sync/TSynchronizedIntList.java new file mode 100644 index 0000000..f8b616c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedIntList extends TSynchronizedIntCollection implements TIntList { + + static final long serialVersionUID = -7754090372962971524L; + + final TIntList list; + + public TSynchronizedIntList(TIntList list) { + super(list); + this.list = list; + } + + public TSynchronizedIntList(TIntList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public int get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public int set(int index, int element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, int[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, int[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public int replace(int offset, int val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public int removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(int[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(int[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, int value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, int[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(int o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(int o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListIntIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListIntIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedIntList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public int[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public int[] toArray(int[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, int value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, int value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(int val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, int val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(int value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TIntList grep(TIntProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TIntList inverseGrep(TIntProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public int max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public int min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public int sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TIntProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessIntList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntLongMap.java new file mode 100644 index 0000000..a7dd7ee --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntLongMap implements TIntLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntLongMap(TIntLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntLongMap(TIntLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(int key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(int key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(int key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntObjectMap.java new file mode 100644 index 0000000..9dca7bb --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntObjectMap implements TIntObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntObjectMap(TIntObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntObjectMap(TIntObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(int key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient Collection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(int key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntSet.java b/src/gnu/trove/impl/sync/TSynchronizedIntSet.java new file mode 100644 index 0000000..ae76069 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedIntSet extends TSynchronizedIntCollection implements TIntSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedIntSet(TIntSet s) { + super(s); + } + + public TSynchronizedIntSet(TIntSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntShortMap.java new file mode 100644 index 0000000..5180a24 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntShortMap implements TIntShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntShortMap(TIntShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntShortMap(TIntShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(int key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(int key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(int key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongByteMap.java new file mode 100644 index 0000000..0b58aad --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongByteMap implements TLongByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongByteMap(TLongByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongByteMap(TLongByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(long key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(long key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongCharMap.java new file mode 100644 index 0000000..e00ec1f --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongCharMap implements TLongCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongCharMap(TLongCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongCharMap(TLongCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(long key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(long key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(long key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongCollection.java b/src/gnu/trove/impl/sync/TSynchronizedLongCollection.java new file mode 100644 index 0000000..3480e5d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongCollection implements TLongCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TLongCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongCollection(TLongCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedLongCollection(TLongCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(long o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public long[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public long[] toArray(long[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TLongIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(long e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(long o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TLongCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(long[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TLongCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(long[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TLongCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(long[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TLongCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(long[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public long getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TLongProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongDoubleMap.java new file mode 100644 index 0000000..9524893 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongDoubleMap implements TLongDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongDoubleMap(TLongDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongDoubleMap(TLongDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(long key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(long key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(long key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongFloatMap.java new file mode 100644 index 0000000..d7bbe6d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongFloatMap implements TLongFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongFloatMap(TLongFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongFloatMap(TLongFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(long key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(long key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(long key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongIntMap.java new file mode 100644 index 0000000..bdd0155 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongIntMap implements TLongIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongIntMap(TLongIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongIntMap(TLongIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(long key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(long key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(long key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongList.java b/src/gnu/trove/impl/sync/TSynchronizedLongList.java new file mode 100644 index 0000000..42d9b00 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedLongList extends TSynchronizedLongCollection implements TLongList { + + static final long serialVersionUID = -7754090372962971524L; + + final TLongList list; + + public TSynchronizedLongList(TLongList list) { + super(list); + this.list = list; + } + + public TSynchronizedLongList(TLongList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public long get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public long set(int index, long element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, long[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, long[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public long replace(int offset, long val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public long removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(long[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(long[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, long value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, long[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(long o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(long o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListLongIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListLongIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedLongList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public long[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public long[] toArray(long[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, long value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, long value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(long val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, long val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(long value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TLongList grep(TLongProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TLongList inverseGrep(TLongProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public long max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public long min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public long sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TLongProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessLongList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongLongMap.java new file mode 100644 index 0000000..c1425e4 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongLongMap implements TLongLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongLongMap(TLongLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongLongMap(TLongLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(long key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(long key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(long key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongObjectMap.java new file mode 100644 index 0000000..8fd1aa6 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongObjectMap implements TLongObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongObjectMap(TLongObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongObjectMap(TLongObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(long key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient Collection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(long key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongSet.java b/src/gnu/trove/impl/sync/TSynchronizedLongSet.java new file mode 100644 index 0000000..9596cc9 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedLongSet extends TSynchronizedLongCollection implements TLongSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedLongSet(TLongSet s) { + super(s); + } + + public TSynchronizedLongSet(TLongSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongShortMap.java new file mode 100644 index 0000000..c9e808e --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongShortMap implements TLongShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongShortMap(TLongShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongShortMap(TLongShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(long key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(long key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(long key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectByteMap.java new file mode 100644 index 0000000..a1157ed --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectByteMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectByteMap implements TObjectByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectByteMap(TObjectByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectByteMap(TObjectByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(K key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TByteCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(K key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(K key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectCharMap.java new file mode 100644 index 0000000..1cf1f93 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectCharMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectCharMap implements TObjectCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectCharMap(TObjectCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectCharMap(TObjectCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(K key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TCharCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(K key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(K key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectDoubleMap.java new file mode 100644 index 0000000..3cecdc3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectDoubleMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectDoubleMap implements TObjectDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectDoubleMap(TObjectDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectDoubleMap(TObjectDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(K key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TDoubleCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(K key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(K key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectFloatMap.java new file mode 100644 index 0000000..dd76251 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectFloatMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectFloatMap implements TObjectFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectFloatMap(TObjectFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectFloatMap(TObjectFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(K key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TFloatCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(K key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(K key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectIntMap.java new file mode 100644 index 0000000..12198ab --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectIntMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectIntMap implements TObjectIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectIntMap(TObjectIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectIntMap(TObjectIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(K key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TIntCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(K key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(K key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectLongMap.java new file mode 100644 index 0000000..8ea682c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectLongMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectLongMap implements TObjectLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectLongMap(TObjectLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectLongMap(TObjectLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(K key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TLongCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(K key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(K key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectShortMap.java new file mode 100644 index 0000000..1d6e92c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectShortMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectShortMap implements TObjectShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectShortMap(TObjectShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectShortMap(TObjectShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(K key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TShortCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(K key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(K key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessByteList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessByteList.java new file mode 100644 index 0000000..1cab757 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessByteList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessByteList extends TSynchronizedByteList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessByteList(TByteList list) { + super(list); + } + + public TSynchronizedRandomAccessByteList(TByteList list, Object mutex) { + super(list, mutex); + } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessByteList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedByteList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessCharList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessCharList.java new file mode 100644 index 0000000..38fcd02 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessCharList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessCharList extends TSynchronizedCharList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessCharList(TCharList list) { + super(list); + } + + public TSynchronizedRandomAccessCharList(TCharList list, Object mutex) { + super(list, mutex); + } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessCharList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedCharList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessDoubleList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessDoubleList.java new file mode 100644 index 0000000..5454458 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessDoubleList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessDoubleList extends TSynchronizedDoubleList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessDoubleList(TDoubleList list) { + super(list); + } + + public TSynchronizedRandomAccessDoubleList(TDoubleList list, Object mutex) { + super(list, mutex); + } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessDoubleList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedDoubleList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessFloatList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessFloatList.java new file mode 100644 index 0000000..3d670a7 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessFloatList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessFloatList extends TSynchronizedFloatList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessFloatList(TFloatList list) { + super(list); + } + + public TSynchronizedRandomAccessFloatList(TFloatList list, Object mutex) { + super(list, mutex); + } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessFloatList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedFloatList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessIntList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessIntList.java new file mode 100644 index 0000000..eb01db2 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessIntList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessIntList extends TSynchronizedIntList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessIntList(TIntList list) { + super(list); + } + + public TSynchronizedRandomAccessIntList(TIntList list, Object mutex) { + super(list, mutex); + } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessIntList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedIntList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessLongList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessLongList.java new file mode 100644 index 0000000..9580cd2 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessLongList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessLongList extends TSynchronizedLongList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessLongList(TLongList list) { + super(list); + } + + public TSynchronizedRandomAccessLongList(TLongList list, Object mutex) { + super(list, mutex); + } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessLongList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedLongList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessShortList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessShortList.java new file mode 100644 index 0000000..2ae9a5a --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessShortList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessShortList extends TSynchronizedShortList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessShortList(TShortList list) { + super(list); + } + + public TSynchronizedRandomAccessShortList(TShortList list, Object mutex) { + super(list, mutex); + } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessShortList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedShortList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortByteMap.java new file mode 100644 index 0000000..145b11d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortByteMap implements TShortByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortByteMap(TShortByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortByteMap(TShortByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(short key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(short key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortCharMap.java new file mode 100644 index 0000000..c898911 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortCharMap implements TShortCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortCharMap(TShortCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortCharMap(TShortCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(short key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(short key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(short key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortCollection.java b/src/gnu/trove/impl/sync/TSynchronizedShortCollection.java new file mode 100644 index 0000000..301a3f7 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortCollection implements TShortCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TShortCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortCollection(TShortCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedShortCollection(TShortCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(short o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public short[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public short[] toArray(short[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TShortIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(short e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(short o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TShortCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(short[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TShortCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(short[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TShortCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(short[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TShortCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(short[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public short getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TShortProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortDoubleMap.java new file mode 100644 index 0000000..0cf6bfd --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortDoubleMap implements TShortDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortDoubleMap(TShortDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortDoubleMap(TShortDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(short key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(short key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(short key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortFloatMap.java new file mode 100644 index 0000000..bb30526 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortFloatMap implements TShortFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortFloatMap(TShortFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortFloatMap(TShortFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(short key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(short key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(short key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortIntMap.java new file mode 100644 index 0000000..8aa6141 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortIntMap implements TShortIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortIntMap(TShortIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortIntMap(TShortIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(short key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(short key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(short key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortList.java b/src/gnu/trove/impl/sync/TSynchronizedShortList.java new file mode 100644 index 0000000..59570d3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedShortList extends TSynchronizedShortCollection implements TShortList { + + static final long serialVersionUID = -7754090372962971524L; + + final TShortList list; + + public TSynchronizedShortList(TShortList list) { + super(list); + this.list = list; + } + + public TSynchronizedShortList(TShortList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public short get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public short set(int index, short element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, short[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, short[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public short replace(int offset, short val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public short removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(short[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(short[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, short value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, short[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(short o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(short o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListShortIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListShortIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedShortList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public short[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public short[] toArray(short[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, short value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, short value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(short val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, short val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(short value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TShortList grep(TShortProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TShortList inverseGrep(TShortProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public short max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public short min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public short sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TShortProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessShortList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortLongMap.java new file mode 100644 index 0000000..e7dcf7d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortLongMap implements TShortLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortLongMap(TShortLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortLongMap(TShortLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(short key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(short key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(short key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortObjectMap.java new file mode 100644 index 0000000..6c43655 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortObjectMap implements TShortObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortObjectMap(TShortObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortObjectMap(TShortObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(short key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient Collection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(short key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortSet.java b/src/gnu/trove/impl/sync/TSynchronizedShortSet.java new file mode 100644 index 0000000..9266646 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedShortSet extends TSynchronizedShortCollection implements TShortSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedShortSet(TShortSet s) { + super(s); + } + + public TSynchronizedShortSet(TShortSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortShortMap.java new file mode 100644 index 0000000..6f5cd74 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortShortMap implements TShortShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortShortMap(TShortShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortShortMap(TShortShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(short key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(short key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(short key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteByteMap.java new file mode 100644 index 0000000..1505442 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteByteMap implements TByteByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteByteMap m; + + public TUnmodifiableByteByteMap(TByteByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(byte key) { + return m.get(key); + } + + @Override + public byte put(byte key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteByteIterator iterator() { + return new TByteByteIterator() { + TByteByteIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(byte key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCharMap.java new file mode 100644 index 0000000..5adabbd --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteCharMap implements TByteCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteCharMap m; + + public TUnmodifiableByteCharMap(TByteCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(byte key) { + return m.get(key); + } + + @Override + public char put(byte key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteCharIterator iterator() { + return new TByteCharIterator() { + TByteCharIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(byte key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCollection.java new file mode 100644 index 0000000..c9537d7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableByteCollection implements TByteCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TByteCollection c; + + public TUnmodifiableByteCollection(TByteCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(byte o) { + return c.contains(o); + } + + @Override + public byte[] toArray() { + return c.toArray(); + } + + @Override + public byte[] toArray(byte[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public byte getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TByteProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TByteIterator iterator() { + return new TByteIterator() { + TByteIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public byte next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(byte e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(byte o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TByteCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(byte[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TByteCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TByteCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TByteCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteDoubleMap.java new file mode 100644 index 0000000..ad6d17c --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteDoubleMap implements TByteDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteDoubleMap m; + + public TUnmodifiableByteDoubleMap(TByteDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(byte key) { + return m.get(key); + } + + @Override + public double put(byte key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteDoubleIterator iterator() { + return new TByteDoubleIterator() { + TByteDoubleIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(byte key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteFloatMap.java new file mode 100644 index 0000000..27f6464 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteFloatMap implements TByteFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteFloatMap m; + + public TUnmodifiableByteFloatMap(TByteFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(byte key) { + return m.get(key); + } + + @Override + public float put(byte key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteFloatIterator iterator() { + return new TByteFloatIterator() { + TByteFloatIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(byte key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteIntMap.java new file mode 100644 index 0000000..2c6b0d7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteIntMap implements TByteIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteIntMap m; + + public TUnmodifiableByteIntMap(TByteIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(byte key) { + return m.get(key); + } + + @Override + public int put(byte key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteIntIterator iterator() { + return new TByteIntIterator() { + TByteIntIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(byte key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteList.java new file mode 100644 index 0000000..724f15c --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableByteList extends TUnmodifiableByteCollection implements TByteList { + static final long serialVersionUID = -283967356065247728L; + + final TByteList list; + + public TUnmodifiableByteList(TByteList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public byte get(int index) { + return list.get(index); + } + + @Override + public int indexOf(byte o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(byte o) { + return list.lastIndexOf(o); + } + + @Override + public byte[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TByteProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(byte value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, byte value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, byte value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TByteList grep(TByteProcedure condition) { + return list.grep(condition); + } + + @Override + public TByteList inverseGrep(TByteProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public byte max() { + return list.max(); + } + + @Override + public byte min() { + return list.min(); + } + + @Override + public byte sum() { + return list.sum(); + } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + return new TUnmodifiableByteList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessByteList(list) : this); + } + + @Override + public void add(byte[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(byte[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public byte removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, byte[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public byte set(int offset, byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, byte[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public byte replace(int offset, byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, byte val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteLongMap.java new file mode 100644 index 0000000..d08c5c9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteLongMap implements TByteLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteLongMap m; + + public TUnmodifiableByteLongMap(TByteLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(byte key) { + return m.get(key); + } + + @Override + public long put(byte key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteLongIterator iterator() { + return new TByteLongIterator() { + TByteLongIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(byte key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteObjectMap.java new file mode 100644 index 0000000..43d2b3b --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableByteObjectMap implements TByteObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteObjectMap m; + + public TUnmodifiableByteObjectMap(TByteObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(byte key) { + return m.get(key); + } + + @Override + public V put(byte key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient Collection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteObjectIterator iterator() { + return new TByteObjectIterator() { + TByteObjectIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(byte key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteSet.java new file mode 100644 index 0000000..e1a67b7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableByteSet extends TUnmodifiableByteCollection implements TByteSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableByteSet(TByteSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteShortMap.java new file mode 100644 index 0000000..43cb0c2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteShortMap implements TByteShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteShortMap m; + + public TUnmodifiableByteShortMap(TByteShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(byte key) { + return m.get(key); + } + + @Override + public short put(byte key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteShortIterator iterator() { + return new TByteShortIterator() { + TByteShortIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(byte key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharByteMap.java new file mode 100644 index 0000000..2349057 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharByteMap implements TCharByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharByteMap m; + + public TUnmodifiableCharByteMap(TCharByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(char key) { + return m.get(key); + } + + @Override + public byte put(char key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharByteIterator iterator() { + return new TCharByteIterator() { + TCharByteIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(char key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCharMap.java new file mode 100644 index 0000000..fbacb4e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharCharMap implements TCharCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharCharMap m; + + public TUnmodifiableCharCharMap(TCharCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(char key) { + return m.get(key); + } + + @Override + public char put(char key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharCharIterator iterator() { + return new TCharCharIterator() { + TCharCharIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(char key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(char key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCollection.java new file mode 100644 index 0000000..efd4e3a --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableCharCollection implements TCharCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TCharCollection c; + + public TUnmodifiableCharCollection(TCharCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(char o) { + return c.contains(o); + } + + @Override + public char[] toArray() { + return c.toArray(); + } + + @Override + public char[] toArray(char[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public char getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TCharProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TCharIterator iterator() { + return new TCharIterator() { + TCharIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public char next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(char e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(char o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TCharCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(char[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TCharCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TCharCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(char[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TCharCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(char[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharDoubleMap.java new file mode 100644 index 0000000..064d1dc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharDoubleMap implements TCharDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharDoubleMap m; + + public TUnmodifiableCharDoubleMap(TCharDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(char key) { + return m.get(key); + } + + @Override + public double put(char key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharDoubleIterator iterator() { + return new TCharDoubleIterator() { + TCharDoubleIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(char key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(char key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharFloatMap.java new file mode 100644 index 0000000..39bbdea --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharFloatMap implements TCharFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharFloatMap m; + + public TUnmodifiableCharFloatMap(TCharFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(char key) { + return m.get(key); + } + + @Override + public float put(char key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharFloatIterator iterator() { + return new TCharFloatIterator() { + TCharFloatIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(char key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(char key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharIntMap.java new file mode 100644 index 0000000..5463e90 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharIntMap implements TCharIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharIntMap m; + + public TUnmodifiableCharIntMap(TCharIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(char key) { + return m.get(key); + } + + @Override + public int put(char key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharIntIterator iterator() { + return new TCharIntIterator() { + TCharIntIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(char key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(char key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharList.java new file mode 100644 index 0000000..dbd5de7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableCharList extends TUnmodifiableCharCollection implements TCharList { + static final long serialVersionUID = -283967356065247728L; + + final TCharList list; + + public TUnmodifiableCharList(TCharList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public char get(int index) { + return list.get(index); + } + + @Override + public int indexOf(char o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(char o) { + return list.lastIndexOf(o); + } + + @Override + public char[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public char[] toArray(char[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TCharProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(char value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, char value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, char value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TCharList grep(TCharProcedure condition) { + return list.grep(condition); + } + + @Override + public TCharList inverseGrep(TCharProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public char max() { + return list.max(); + } + + @Override + public char min() { + return list.min(); + } + + @Override + public char sum() { + return list.sum(); + } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + return new TUnmodifiableCharList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessCharList(list) : this); + } + + @Override + public void add(char[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(char[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public char removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, char[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public char set(int offset, char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, char[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, char[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public char replace(int offset, char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, char val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharLongMap.java new file mode 100644 index 0000000..c8189e6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharLongMap implements TCharLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharLongMap m; + + public TUnmodifiableCharLongMap(TCharLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(char key) { + return m.get(key); + } + + @Override + public long put(char key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharLongIterator iterator() { + return new TCharLongIterator() { + TCharLongIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(char key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(char key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharObjectMap.java new file mode 100644 index 0000000..484d8ad --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableCharObjectMap implements TCharObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharObjectMap m; + + public TUnmodifiableCharObjectMap(TCharObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(char key) { + return m.get(key); + } + + @Override + public V put(char key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient Collection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharObjectIterator iterator() { + return new TCharObjectIterator() { + TCharObjectIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(char key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharSet.java new file mode 100644 index 0000000..c15c732 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableCharSet extends TUnmodifiableCharCollection implements TCharSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableCharSet(TCharSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharShortMap.java new file mode 100644 index 0000000..f7ff877 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharShortMap implements TCharShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharShortMap m; + + public TUnmodifiableCharShortMap(TCharShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(char key) { + return m.get(key); + } + + @Override + public short put(char key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharShortIterator iterator() { + return new TCharShortIterator() { + TCharShortIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(char key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(char key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleByteMap.java new file mode 100644 index 0000000..ae6d281 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleByteMap implements TDoubleByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleByteMap m; + + public TUnmodifiableDoubleByteMap(TDoubleByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(double key) { + return m.get(key); + } + + @Override + public byte put(double key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleByteIterator iterator() { + return new TDoubleByteIterator() { + TDoubleByteIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(double key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCharMap.java new file mode 100644 index 0000000..473e4e9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleCharMap implements TDoubleCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleCharMap m; + + public TUnmodifiableDoubleCharMap(TDoubleCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(double key) { + return m.get(key); + } + + @Override + public char put(double key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleCharIterator iterator() { + return new TDoubleCharIterator() { + TDoubleCharIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(double key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(double key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCollection.java new file mode 100644 index 0000000..cd82ed0 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableDoubleCollection implements TDoubleCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TDoubleCollection c; + + public TUnmodifiableDoubleCollection(TDoubleCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(double o) { + return c.contains(o); + } + + @Override + public double[] toArray() { + return c.toArray(); + } + + @Override + public double[] toArray(double[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public double getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TDoubleProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TDoubleIterator iterator() { + return new TDoubleIterator() { + TDoubleIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public double next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(double e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(double o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TDoubleCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(double[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TDoubleCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TDoubleCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(double[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TDoubleCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(double[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleDoubleMap.java new file mode 100644 index 0000000..07152ab --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleDoubleMap implements TDoubleDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleDoubleMap m; + + public TUnmodifiableDoubleDoubleMap(TDoubleDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(double key) { + return m.get(key); + } + + @Override + public double put(double key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleDoubleIterator iterator() { + return new TDoubleDoubleIterator() { + TDoubleDoubleIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(double key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(double key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleFloatMap.java new file mode 100644 index 0000000..ee6145f --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleFloatMap implements TDoubleFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleFloatMap m; + + public TUnmodifiableDoubleFloatMap(TDoubleFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(double key) { + return m.get(key); + } + + @Override + public float put(double key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleFloatIterator iterator() { + return new TDoubleFloatIterator() { + TDoubleFloatIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(double key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(double key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleIntMap.java new file mode 100644 index 0000000..18986f3 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleIntMap implements TDoubleIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleIntMap m; + + public TUnmodifiableDoubleIntMap(TDoubleIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(double key) { + return m.get(key); + } + + @Override + public int put(double key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleIntIterator iterator() { + return new TDoubleIntIterator() { + TDoubleIntIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(double key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(double key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleList.java new file mode 100644 index 0000000..ee6707e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableDoubleList extends TUnmodifiableDoubleCollection implements TDoubleList { + static final long serialVersionUID = -283967356065247728L; + + final TDoubleList list; + + public TUnmodifiableDoubleList(TDoubleList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public double get(int index) { + return list.get(index); + } + + @Override + public int indexOf(double o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(double o) { + return list.lastIndexOf(o); + } + + @Override + public double[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public double[] toArray(double[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(double value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, double value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, double value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TDoubleList grep(TDoubleProcedure condition) { + return list.grep(condition); + } + + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public double max() { + return list.max(); + } + + @Override + public double min() { + return list.min(); + } + + @Override + public double sum() { + return list.sum(); + } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + return new TUnmodifiableDoubleList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessDoubleList(list) : this); + } + + @Override + public void add(double[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(double[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public double removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, double[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public double set(int offset, double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, double[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, double[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public double replace(int offset, double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, double val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleLongMap.java new file mode 100644 index 0000000..8a6f3e5 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleLongMap implements TDoubleLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleLongMap m; + + public TUnmodifiableDoubleLongMap(TDoubleLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(double key) { + return m.get(key); + } + + @Override + public long put(double key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleLongIterator iterator() { + return new TDoubleLongIterator() { + TDoubleLongIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(double key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(double key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleObjectMap.java new file mode 100644 index 0000000..3e5125f --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableDoubleObjectMap implements TDoubleObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleObjectMap m; + + public TUnmodifiableDoubleObjectMap(TDoubleObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(double key) { + return m.get(key); + } + + @Override + public V put(double key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient Collection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleObjectIterator iterator() { + return new TDoubleObjectIterator() { + TDoubleObjectIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(double key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleSet.java new file mode 100644 index 0000000..c171edb --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableDoubleSet extends TUnmodifiableDoubleCollection implements TDoubleSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableDoubleSet(TDoubleSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleShortMap.java new file mode 100644 index 0000000..8569f3f --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleShortMap implements TDoubleShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleShortMap m; + + public TUnmodifiableDoubleShortMap(TDoubleShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(double key) { + return m.get(key); + } + + @Override + public short put(double key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleShortIterator iterator() { + return new TDoubleShortIterator() { + TDoubleShortIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(double key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(double key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatByteMap.java new file mode 100644 index 0000000..f97245e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatByteMap implements TFloatByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatByteMap m; + + public TUnmodifiableFloatByteMap(TFloatByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(float key) { + return m.get(key); + } + + @Override + public byte put(float key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatByteIterator iterator() { + return new TFloatByteIterator() { + TFloatByteIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(float key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCharMap.java new file mode 100644 index 0000000..9e7a6d6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatCharMap implements TFloatCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatCharMap m; + + public TUnmodifiableFloatCharMap(TFloatCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(float key) { + return m.get(key); + } + + @Override + public char put(float key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatCharIterator iterator() { + return new TFloatCharIterator() { + TFloatCharIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(float key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(float key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCollection.java new file mode 100644 index 0000000..7e45d4e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableFloatCollection implements TFloatCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TFloatCollection c; + + public TUnmodifiableFloatCollection(TFloatCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(float o) { + return c.contains(o); + } + + @Override + public float[] toArray() { + return c.toArray(); + } + + @Override + public float[] toArray(float[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public float getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TFloatProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TFloatIterator iterator() { + return new TFloatIterator() { + TFloatIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public float next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(float e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(float o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TFloatCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(float[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TFloatCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TFloatCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(float[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TFloatCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(float[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatDoubleMap.java new file mode 100644 index 0000000..691b486 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatDoubleMap implements TFloatDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatDoubleMap m; + + public TUnmodifiableFloatDoubleMap(TFloatDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(float key) { + return m.get(key); + } + + @Override + public double put(float key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatDoubleIterator iterator() { + return new TFloatDoubleIterator() { + TFloatDoubleIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(float key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(float key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatFloatMap.java new file mode 100644 index 0000000..f6ba251 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatFloatMap implements TFloatFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatFloatMap m; + + public TUnmodifiableFloatFloatMap(TFloatFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(float key) { + return m.get(key); + } + + @Override + public float put(float key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatFloatIterator iterator() { + return new TFloatFloatIterator() { + TFloatFloatIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(float key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(float key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatIntMap.java new file mode 100644 index 0000000..87dbbc2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatIntMap implements TFloatIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatIntMap m; + + public TUnmodifiableFloatIntMap(TFloatIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(float key) { + return m.get(key); + } + + @Override + public int put(float key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatIntIterator iterator() { + return new TFloatIntIterator() { + TFloatIntIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(float key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(float key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatList.java new file mode 100644 index 0000000..ffb9dbc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableFloatList extends TUnmodifiableFloatCollection implements TFloatList { + static final long serialVersionUID = -283967356065247728L; + + final TFloatList list; + + public TUnmodifiableFloatList(TFloatList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public float get(int index) { + return list.get(index); + } + + @Override + public int indexOf(float o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(float o) { + return list.lastIndexOf(o); + } + + @Override + public float[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public float[] toArray(float[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(float value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, float value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, float value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TFloatList grep(TFloatProcedure condition) { + return list.grep(condition); + } + + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public float max() { + return list.max(); + } + + @Override + public float min() { + return list.min(); + } + + @Override + public float sum() { + return list.sum(); + } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + return new TUnmodifiableFloatList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessFloatList(list) : this); + } + + @Override + public void add(float[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(float[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public float removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, float[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public float set(int offset, float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, float[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, float[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public float replace(int offset, float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, float val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatLongMap.java new file mode 100644 index 0000000..fd51057 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatLongMap implements TFloatLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatLongMap m; + + public TUnmodifiableFloatLongMap(TFloatLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(float key) { + return m.get(key); + } + + @Override + public long put(float key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatLongIterator iterator() { + return new TFloatLongIterator() { + TFloatLongIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(float key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(float key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatObjectMap.java new file mode 100644 index 0000000..0df1073 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableFloatObjectMap implements TFloatObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatObjectMap m; + + public TUnmodifiableFloatObjectMap(TFloatObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(float key) { + return m.get(key); + } + + @Override + public V put(float key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient Collection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatObjectIterator iterator() { + return new TFloatObjectIterator() { + TFloatObjectIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(float key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatSet.java new file mode 100644 index 0000000..886e8c5 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableFloatSet extends TUnmodifiableFloatCollection implements TFloatSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableFloatSet(TFloatSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatShortMap.java new file mode 100644 index 0000000..8600dfc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatShortMap implements TFloatShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatShortMap m; + + public TUnmodifiableFloatShortMap(TFloatShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(float key) { + return m.get(key); + } + + @Override + public short put(float key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatShortIterator iterator() { + return new TFloatShortIterator() { + TFloatShortIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(float key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(float key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntByteMap.java new file mode 100644 index 0000000..c519991 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntByteMap implements TIntByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntByteMap m; + + public TUnmodifiableIntByteMap(TIntByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(int key) { + return m.get(key); + } + + @Override + public byte put(int key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntByteIterator iterator() { + return new TIntByteIterator() { + TIntByteIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(int key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCharMap.java new file mode 100644 index 0000000..b7ad673 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntCharMap implements TIntCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntCharMap m; + + public TUnmodifiableIntCharMap(TIntCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(int key) { + return m.get(key); + } + + @Override + public char put(int key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntCharIterator iterator() { + return new TIntCharIterator() { + TIntCharIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(int key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(int key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCollection.java new file mode 100644 index 0000000..93c6a90 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableIntCollection implements TIntCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TIntCollection c; + + public TUnmodifiableIntCollection(TIntCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(int o) { + return c.contains(o); + } + + @Override + public int[] toArray() { + return c.toArray(); + } + + @Override + public int[] toArray(int[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public int getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TIntProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TIntIterator iterator() { + return new TIntIterator() { + TIntIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public int next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(int e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(int o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TIntCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(int[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TIntCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TIntCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TIntCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntDoubleMap.java new file mode 100644 index 0000000..1b87709 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntDoubleMap implements TIntDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntDoubleMap m; + + public TUnmodifiableIntDoubleMap(TIntDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(int key) { + return m.get(key); + } + + @Override + public double put(int key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntDoubleIterator iterator() { + return new TIntDoubleIterator() { + TIntDoubleIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(int key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(int key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntFloatMap.java new file mode 100644 index 0000000..0ff22dc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntFloatMap implements TIntFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntFloatMap m; + + public TUnmodifiableIntFloatMap(TIntFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(int key) { + return m.get(key); + } + + @Override + public float put(int key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntFloatIterator iterator() { + return new TIntFloatIterator() { + TIntFloatIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(int key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(int key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntIntMap.java new file mode 100644 index 0000000..ad43bb4 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntIntMap implements TIntIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntIntMap m; + + public TUnmodifiableIntIntMap(TIntIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(int key) { + return m.get(key); + } + + @Override + public int put(int key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntIntIterator iterator() { + return new TIntIntIterator() { + TIntIntIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(int key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(int key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntList.java new file mode 100644 index 0000000..089fb2a --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableIntList extends TUnmodifiableIntCollection implements TIntList { + static final long serialVersionUID = -283967356065247728L; + + final TIntList list; + + public TUnmodifiableIntList(TIntList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public int get(int index) { + return list.get(index); + } + + @Override + public int indexOf(int o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(int o) { + return list.lastIndexOf(o); + } + + @Override + public int[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public int[] toArray(int[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TIntProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(int value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, int value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, int value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TIntList grep(TIntProcedure condition) { + return list.grep(condition); + } + + @Override + public TIntList inverseGrep(TIntProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public int max() { + return list.max(); + } + + @Override + public int min() { + return list.min(); + } + + @Override + public int sum() { + return list.sum(); + } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + return new TUnmodifiableIntList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessIntList(list) : this); + } + + @Override + public void add(int[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(int[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public int removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, int[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public int set(int offset, int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, int[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, int[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public int replace(int offset, int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, int val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntLongMap.java new file mode 100644 index 0000000..3e8ebf9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntLongMap implements TIntLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntLongMap m; + + public TUnmodifiableIntLongMap(TIntLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(int key) { + return m.get(key); + } + + @Override + public long put(int key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntLongIterator iterator() { + return new TIntLongIterator() { + TIntLongIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(int key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(int key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntObjectMap.java new file mode 100644 index 0000000..067cf69 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableIntObjectMap implements TIntObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntObjectMap m; + + public TUnmodifiableIntObjectMap(TIntObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(int key) { + return m.get(key); + } + + @Override + public V put(int key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient Collection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntObjectIterator iterator() { + return new TIntObjectIterator() { + TIntObjectIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(int key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntSet.java new file mode 100644 index 0000000..a924fbf --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableIntSet extends TUnmodifiableIntCollection implements TIntSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableIntSet(TIntSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntShortMap.java new file mode 100644 index 0000000..9751db2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntShortMap implements TIntShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntShortMap m; + + public TUnmodifiableIntShortMap(TIntShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(int key) { + return m.get(key); + } + + @Override + public short put(int key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntShortIterator iterator() { + return new TIntShortIterator() { + TIntShortIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(int key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(int key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongByteMap.java new file mode 100644 index 0000000..6d475f6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongByteMap implements TLongByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongByteMap m; + + public TUnmodifiableLongByteMap(TLongByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(long key) { + return m.get(key); + } + + @Override + public byte put(long key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongByteIterator iterator() { + return new TLongByteIterator() { + TLongByteIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(long key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCharMap.java new file mode 100644 index 0000000..723da6d --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongCharMap implements TLongCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongCharMap m; + + public TUnmodifiableLongCharMap(TLongCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(long key) { + return m.get(key); + } + + @Override + public char put(long key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongCharIterator iterator() { + return new TLongCharIterator() { + TLongCharIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(long key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(long key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCollection.java new file mode 100644 index 0000000..f71be15 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableLongCollection implements TLongCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TLongCollection c; + + public TUnmodifiableLongCollection(TLongCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(long o) { + return c.contains(o); + } + + @Override + public long[] toArray() { + return c.toArray(); + } + + @Override + public long[] toArray(long[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public long getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TLongProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TLongIterator iterator() { + return new TLongIterator() { + TLongIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public long next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(long e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(long o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TLongCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(long[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TLongCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TLongCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TLongCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongDoubleMap.java new file mode 100644 index 0000000..7c82256 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongDoubleMap implements TLongDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongDoubleMap m; + + public TUnmodifiableLongDoubleMap(TLongDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(long key) { + return m.get(key); + } + + @Override + public double put(long key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongDoubleIterator iterator() { + return new TLongDoubleIterator() { + TLongDoubleIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(long key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(long key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongFloatMap.java new file mode 100644 index 0000000..3401b25 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongFloatMap implements TLongFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongFloatMap m; + + public TUnmodifiableLongFloatMap(TLongFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(long key) { + return m.get(key); + } + + @Override + public float put(long key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongFloatIterator iterator() { + return new TLongFloatIterator() { + TLongFloatIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(long key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(long key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongIntMap.java new file mode 100644 index 0000000..a1c0742 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongIntMap implements TLongIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongIntMap m; + + public TUnmodifiableLongIntMap(TLongIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(long key) { + return m.get(key); + } + + @Override + public int put(long key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongIntIterator iterator() { + return new TLongIntIterator() { + TLongIntIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(long key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(long key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongList.java new file mode 100644 index 0000000..c3ba351 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableLongList extends TUnmodifiableLongCollection implements TLongList { + static final long serialVersionUID = -283967356065247728L; + + final TLongList list; + + public TUnmodifiableLongList(TLongList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public long get(int index) { + return list.get(index); + } + + @Override + public int indexOf(long o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(long o) { + return list.lastIndexOf(o); + } + + @Override + public long[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public long[] toArray(long[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TLongProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(long value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, long value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, long value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TLongList grep(TLongProcedure condition) { + return list.grep(condition); + } + + @Override + public TLongList inverseGrep(TLongProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public long max() { + return list.max(); + } + + @Override + public long min() { + return list.min(); + } + + @Override + public long sum() { + return list.sum(); + } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + return new TUnmodifiableLongList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessLongList(list) : this); + } + + @Override + public void add(long[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(long[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public long removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, long[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public long set(int offset, long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, long[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, long[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public long replace(int offset, long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, long val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongLongMap.java new file mode 100644 index 0000000..8ab49dc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongLongMap implements TLongLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongLongMap m; + + public TUnmodifiableLongLongMap(TLongLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(long key) { + return m.get(key); + } + + @Override + public long put(long key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongLongIterator iterator() { + return new TLongLongIterator() { + TLongLongIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(long key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(long key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongObjectMap.java new file mode 100644 index 0000000..25c6c66 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableLongObjectMap implements TLongObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongObjectMap m; + + public TUnmodifiableLongObjectMap(TLongObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(long key) { + return m.get(key); + } + + @Override + public V put(long key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient Collection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongObjectIterator iterator() { + return new TLongObjectIterator() { + TLongObjectIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(long key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongSet.java new file mode 100644 index 0000000..2bda514 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableLongSet extends TUnmodifiableLongCollection implements TLongSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableLongSet(TLongSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongShortMap.java new file mode 100644 index 0000000..c91df9e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongShortMap implements TLongShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongShortMap m; + + public TUnmodifiableLongShortMap(TLongShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(long key) { + return m.get(key); + } + + @Override + public short put(long key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongShortIterator iterator() { + return new TLongShortIterator() { + TLongShortIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(long key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(long key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectByteMap.java new file mode 100644 index 0000000..6368c21 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectByteMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectByteMap implements TObjectByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectByteMap m; + + public TUnmodifiableObjectByteMap(TObjectByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(Object key) { + return m.get(key); + } + + @Override + public byte put(K key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TByteCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectByteIterator iterator() { + return new TObjectByteIterator() { + TObjectByteIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(K key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(K key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectCharMap.java new file mode 100644 index 0000000..f12fb07 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectCharMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectCharMap implements TObjectCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectCharMap m; + + public TUnmodifiableObjectCharMap(TObjectCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(Object key) { + return m.get(key); + } + + @Override + public char put(K key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TCharCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectCharIterator iterator() { + return new TObjectCharIterator() { + TObjectCharIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(K key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(K key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectDoubleMap.java new file mode 100644 index 0000000..0e8c801 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectDoubleMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectDoubleMap implements TObjectDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectDoubleMap m; + + public TUnmodifiableObjectDoubleMap(TObjectDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(Object key) { + return m.get(key); + } + + @Override + public double put(K key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TDoubleCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectDoubleIterator iterator() { + return new TObjectDoubleIterator() { + TObjectDoubleIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(K key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(K key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectFloatMap.java new file mode 100644 index 0000000..7560ca4 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectFloatMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectFloatMap implements TObjectFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectFloatMap m; + + public TUnmodifiableObjectFloatMap(TObjectFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(Object key) { + return m.get(key); + } + + @Override + public float put(K key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TFloatCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectFloatIterator iterator() { + return new TObjectFloatIterator() { + TObjectFloatIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(K key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(K key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectIntMap.java new file mode 100644 index 0000000..ab5e398 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectIntMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectIntMap implements TObjectIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectIntMap m; + + public TUnmodifiableObjectIntMap(TObjectIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(Object key) { + return m.get(key); + } + + @Override + public int put(K key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TIntCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectIntIterator iterator() { + return new TObjectIntIterator() { + TObjectIntIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(K key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(K key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectLongMap.java new file mode 100644 index 0000000..af0aa5d --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectLongMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectLongMap implements TObjectLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectLongMap m; + + public TUnmodifiableObjectLongMap(TObjectLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(Object key) { + return m.get(key); + } + + @Override + public long put(K key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TLongCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectLongIterator iterator() { + return new TObjectLongIterator() { + TObjectLongIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(K key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(K key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectShortMap.java new file mode 100644 index 0000000..d199d23 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectShortMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectShortMap implements TObjectShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectShortMap m; + + public TUnmodifiableObjectShortMap(TObjectShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(Object key) { + return m.get(key); + } + + @Override + public short put(K key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TShortCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectShortIterator iterator() { + return new TObjectShortIterator() { + TObjectShortIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(K key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(K key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessByteList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessByteList.java new file mode 100644 index 0000000..2146663 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessByteList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessByteList extends TUnmodifiableByteList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessByteList(TByteList list) { + super(list); + } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessByteList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableByteList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessCharList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessCharList.java new file mode 100644 index 0000000..6e62a7b --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessCharList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessCharList extends TUnmodifiableCharList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessCharList(TCharList list) { + super(list); + } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessCharList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableCharList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessDoubleList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessDoubleList.java new file mode 100644 index 0000000..5e0b826 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessDoubleList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessDoubleList extends TUnmodifiableDoubleList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessDoubleList(TDoubleList list) { + super(list); + } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessDoubleList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableDoubleList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessFloatList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessFloatList.java new file mode 100644 index 0000000..d024238 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessFloatList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessFloatList extends TUnmodifiableFloatList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessFloatList(TFloatList list) { + super(list); + } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessFloatList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableFloatList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessIntList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessIntList.java new file mode 100644 index 0000000..7322e68 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessIntList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessIntList extends TUnmodifiableIntList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessIntList(TIntList list) { + super(list); + } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessIntList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableIntList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessLongList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessLongList.java new file mode 100644 index 0000000..97b1f18 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessLongList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessLongList extends TUnmodifiableLongList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessLongList(TLongList list) { + super(list); + } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessLongList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableLongList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessShortList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessShortList.java new file mode 100644 index 0000000..f4d8577 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessShortList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessShortList extends TUnmodifiableShortList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessShortList(TShortList list) { + super(list); + } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessShortList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableShortList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortByteMap.java new file mode 100644 index 0000000..428f167 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortByteMap implements TShortByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortByteMap m; + + public TUnmodifiableShortByteMap(TShortByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(short key) { + return m.get(key); + } + + @Override + public byte put(short key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortByteIterator iterator() { + return new TShortByteIterator() { + TShortByteIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(short key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCharMap.java new file mode 100644 index 0000000..3c20369 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortCharMap implements TShortCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortCharMap m; + + public TUnmodifiableShortCharMap(TShortCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(short key) { + return m.get(key); + } + + @Override + public char put(short key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortCharIterator iterator() { + return new TShortCharIterator() { + TShortCharIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(short key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(short key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCollection.java new file mode 100644 index 0000000..b5280cd --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableShortCollection implements TShortCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TShortCollection c; + + public TUnmodifiableShortCollection(TShortCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(short o) { + return c.contains(o); + } + + @Override + public short[] toArray() { + return c.toArray(); + } + + @Override + public short[] toArray(short[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public short getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TShortProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TShortIterator iterator() { + return new TShortIterator() { + TShortIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public short next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(short e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(short o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TShortCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(short[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TShortCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TShortCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(short[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TShortCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(short[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortDoubleMap.java new file mode 100644 index 0000000..ad833a2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortDoubleMap implements TShortDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortDoubleMap m; + + public TUnmodifiableShortDoubleMap(TShortDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(short key) { + return m.get(key); + } + + @Override + public double put(short key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortDoubleIterator iterator() { + return new TShortDoubleIterator() { + TShortDoubleIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(short key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(short key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortFloatMap.java new file mode 100644 index 0000000..fc2dca6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortFloatMap implements TShortFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortFloatMap m; + + public TUnmodifiableShortFloatMap(TShortFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(short key) { + return m.get(key); + } + + @Override + public float put(short key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortFloatIterator iterator() { + return new TShortFloatIterator() { + TShortFloatIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(short key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(short key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortIntMap.java new file mode 100644 index 0000000..a8d47d9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortIntMap implements TShortIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortIntMap m; + + public TUnmodifiableShortIntMap(TShortIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(short key) { + return m.get(key); + } + + @Override + public int put(short key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortIntIterator iterator() { + return new TShortIntIterator() { + TShortIntIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(short key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(short key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortList.java new file mode 100644 index 0000000..f28a3ff --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableShortList extends TUnmodifiableShortCollection implements TShortList { + static final long serialVersionUID = -283967356065247728L; + + final TShortList list; + + public TUnmodifiableShortList(TShortList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public short get(int index) { + return list.get(index); + } + + @Override + public int indexOf(short o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(short o) { + return list.lastIndexOf(o); + } + + @Override + public short[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public short[] toArray(short[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TShortProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(short value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, short value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, short value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TShortList grep(TShortProcedure condition) { + return list.grep(condition); + } + + @Override + public TShortList inverseGrep(TShortProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public short max() { + return list.max(); + } + + @Override + public short min() { + return list.min(); + } + + @Override + public short sum() { + return list.sum(); + } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + return new TUnmodifiableShortList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessShortList(list) : this); + } + + @Override + public void add(short[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(short[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public short removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, short[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public short set(int offset, short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, short[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, short[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public short replace(int offset, short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, short val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortLongMap.java new file mode 100644 index 0000000..268a550 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortLongMap implements TShortLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortLongMap m; + + public TUnmodifiableShortLongMap(TShortLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(short key) { + return m.get(key); + } + + @Override + public long put(short key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortLongIterator iterator() { + return new TShortLongIterator() { + TShortLongIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(short key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(short key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortObjectMap.java new file mode 100644 index 0000000..f9ae332 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableShortObjectMap implements TShortObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortObjectMap m; + + public TUnmodifiableShortObjectMap(TShortObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(short key) { + return m.get(key); + } + + @Override + public V put(short key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient Collection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortObjectIterator iterator() { + return new TShortObjectIterator() { + TShortObjectIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(short key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortSet.java new file mode 100644 index 0000000..553363e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableShortSet extends TUnmodifiableShortCollection implements TShortSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableShortSet(TShortSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortShortMap.java new file mode 100644 index 0000000..cff10c6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortShortMap implements TShortShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortShortMap m; + + public TUnmodifiableShortShortMap(TShortShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(short key) { + return m.get(key); + } + + @Override + public short put(short key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortShortIterator iterator() { + return new TShortShortIterator() { + TShortShortIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(short key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(short key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/iterator/TAdvancingIterator.java b/src/gnu/trove/iterator/TAdvancingIterator.java new file mode 100644 index 0000000..1b4c195 --- /dev/null +++ b/src/gnu/trove/iterator/TAdvancingIterator.java @@ -0,0 +1,32 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// +package gnu.trove.iterator; + +/** + * Common interface for iterators that operate via the "advance" method for + * moving the cursor to the next element. + */ +public interface TAdvancingIterator extends TIterator { + /** + * Moves the iterator forward to the next entry. + * + * @throws java.util.NoSuchElementException + * if the iterator is already exhausted + */ + public void advance(); +} diff --git a/src/gnu/trove/iterator/TByteByteIterator.java b/src/gnu/trove/iterator/TByteByteIterator.java new file mode 100644 index 0000000..60320a9 --- /dev/null +++ b/src/gnu/trove/iterator/TByteByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TByteCharIterator.java b/src/gnu/trove/iterator/TByteCharIterator.java new file mode 100644 index 0000000..dcf3ea2 --- /dev/null +++ b/src/gnu/trove/iterator/TByteCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TByteDoubleIterator.java b/src/gnu/trove/iterator/TByteDoubleIterator.java new file mode 100644 index 0000000..8b91050 --- /dev/null +++ b/src/gnu/trove/iterator/TByteDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TByteFloatIterator.java b/src/gnu/trove/iterator/TByteFloatIterator.java new file mode 100644 index 0000000..e9d048a --- /dev/null +++ b/src/gnu/trove/iterator/TByteFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TByteIntIterator.java b/src/gnu/trove/iterator/TByteIntIterator.java new file mode 100644 index 0000000..037c21c --- /dev/null +++ b/src/gnu/trove/iterator/TByteIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TByteIterator.java b/src/gnu/trove/iterator/TByteIterator.java new file mode 100644 index 0000000..62bf5be --- /dev/null +++ b/src/gnu/trove/iterator/TByteIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for byte collections. + */ +public interface TByteIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next byte in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public byte next(); +} diff --git a/src/gnu/trove/iterator/TByteLongIterator.java b/src/gnu/trove/iterator/TByteLongIterator.java new file mode 100644 index 0000000..43a803f --- /dev/null +++ b/src/gnu/trove/iterator/TByteLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TByteObjectIterator.java b/src/gnu/trove/iterator/TByteObjectIterator.java new file mode 100644 index 0000000..e3f585e --- /dev/null +++ b/src/gnu/trove/iterator/TByteObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TByteObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TByteObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TByteObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TByteObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TByteObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TByteShortIterator.java b/src/gnu/trove/iterator/TByteShortIterator.java new file mode 100644 index 0000000..6e290b0 --- /dev/null +++ b/src/gnu/trove/iterator/TByteShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TCharByteIterator.java b/src/gnu/trove/iterator/TCharByteIterator.java new file mode 100644 index 0000000..25178e9 --- /dev/null +++ b/src/gnu/trove/iterator/TCharByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TCharCharIterator.java b/src/gnu/trove/iterator/TCharCharIterator.java new file mode 100644 index 0000000..3f46990 --- /dev/null +++ b/src/gnu/trove/iterator/TCharCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TCharDoubleIterator.java b/src/gnu/trove/iterator/TCharDoubleIterator.java new file mode 100644 index 0000000..2a34dfd --- /dev/null +++ b/src/gnu/trove/iterator/TCharDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TCharFloatIterator.java b/src/gnu/trove/iterator/TCharFloatIterator.java new file mode 100644 index 0000000..6cee311 --- /dev/null +++ b/src/gnu/trove/iterator/TCharFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TCharIntIterator.java b/src/gnu/trove/iterator/TCharIntIterator.java new file mode 100644 index 0000000..82fdb12 --- /dev/null +++ b/src/gnu/trove/iterator/TCharIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TCharIterator.java b/src/gnu/trove/iterator/TCharIterator.java new file mode 100644 index 0000000..dfdf38f --- /dev/null +++ b/src/gnu/trove/iterator/TCharIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for char collections. + */ +public interface TCharIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next char in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public char next(); +} diff --git a/src/gnu/trove/iterator/TCharLongIterator.java b/src/gnu/trove/iterator/TCharLongIterator.java new file mode 100644 index 0000000..c8f9a78 --- /dev/null +++ b/src/gnu/trove/iterator/TCharLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TCharObjectIterator.java b/src/gnu/trove/iterator/TCharObjectIterator.java new file mode 100644 index 0000000..3e2d9e5 --- /dev/null +++ b/src/gnu/trove/iterator/TCharObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TCharObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TCharObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TCharObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TCharObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TCharObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TCharShortIterator.java b/src/gnu/trove/iterator/TCharShortIterator.java new file mode 100644 index 0000000..3f46bad --- /dev/null +++ b/src/gnu/trove/iterator/TCharShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TDoubleByteIterator.java b/src/gnu/trove/iterator/TDoubleByteIterator.java new file mode 100644 index 0000000..fff6444 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TDoubleCharIterator.java b/src/gnu/trove/iterator/TDoubleCharIterator.java new file mode 100644 index 0000000..2e0e2ca --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TDoubleDoubleIterator.java b/src/gnu/trove/iterator/TDoubleDoubleIterator.java new file mode 100644 index 0000000..515522f --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TDoubleFloatIterator.java b/src/gnu/trove/iterator/TDoubleFloatIterator.java new file mode 100644 index 0000000..0324399 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TDoubleIntIterator.java b/src/gnu/trove/iterator/TDoubleIntIterator.java new file mode 100644 index 0000000..64a12b4 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TDoubleIterator.java b/src/gnu/trove/iterator/TDoubleIterator.java new file mode 100644 index 0000000..792e359 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for double collections. + */ +public interface TDoubleIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next double in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public double next(); +} diff --git a/src/gnu/trove/iterator/TDoubleLongIterator.java b/src/gnu/trove/iterator/TDoubleLongIterator.java new file mode 100644 index 0000000..1d2385e --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TDoubleObjectIterator.java b/src/gnu/trove/iterator/TDoubleObjectIterator.java new file mode 100644 index 0000000..bce9020 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TDoubleObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TDoubleObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TDoubleObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TDoubleObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TDoubleObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TDoubleShortIterator.java b/src/gnu/trove/iterator/TDoubleShortIterator.java new file mode 100644 index 0000000..6010074 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TFloatByteIterator.java b/src/gnu/trove/iterator/TFloatByteIterator.java new file mode 100644 index 0000000..17c5051 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TFloatCharIterator.java b/src/gnu/trove/iterator/TFloatCharIterator.java new file mode 100644 index 0000000..17d8cc8 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TFloatDoubleIterator.java b/src/gnu/trove/iterator/TFloatDoubleIterator.java new file mode 100644 index 0000000..dbeedf2 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TFloatFloatIterator.java b/src/gnu/trove/iterator/TFloatFloatIterator.java new file mode 100644 index 0000000..985679c --- /dev/null +++ b/src/gnu/trove/iterator/TFloatFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TFloatIntIterator.java b/src/gnu/trove/iterator/TFloatIntIterator.java new file mode 100644 index 0000000..7cba419 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TFloatIterator.java b/src/gnu/trove/iterator/TFloatIterator.java new file mode 100644 index 0000000..39bbd18 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for float collections. + */ +public interface TFloatIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next float in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public float next(); +} diff --git a/src/gnu/trove/iterator/TFloatLongIterator.java b/src/gnu/trove/iterator/TFloatLongIterator.java new file mode 100644 index 0000000..df16828 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TFloatObjectIterator.java b/src/gnu/trove/iterator/TFloatObjectIterator.java new file mode 100644 index 0000000..d2b2344 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TFloatObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TFloatObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TFloatObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TFloatObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TFloatObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TFloatShortIterator.java b/src/gnu/trove/iterator/TFloatShortIterator.java new file mode 100644 index 0000000..3a1eb98 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TIntByteIterator.java b/src/gnu/trove/iterator/TIntByteIterator.java new file mode 100644 index 0000000..caf7ab1 --- /dev/null +++ b/src/gnu/trove/iterator/TIntByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TIntCharIterator.java b/src/gnu/trove/iterator/TIntCharIterator.java new file mode 100644 index 0000000..27f760f --- /dev/null +++ b/src/gnu/trove/iterator/TIntCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TIntDoubleIterator.java b/src/gnu/trove/iterator/TIntDoubleIterator.java new file mode 100644 index 0000000..57b8792 --- /dev/null +++ b/src/gnu/trove/iterator/TIntDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TIntFloatIterator.java b/src/gnu/trove/iterator/TIntFloatIterator.java new file mode 100644 index 0000000..a262687 --- /dev/null +++ b/src/gnu/trove/iterator/TIntFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TIntIntIterator.java b/src/gnu/trove/iterator/TIntIntIterator.java new file mode 100644 index 0000000..a2e2129 --- /dev/null +++ b/src/gnu/trove/iterator/TIntIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TIntIterator.java b/src/gnu/trove/iterator/TIntIterator.java new file mode 100644 index 0000000..30b2c3d --- /dev/null +++ b/src/gnu/trove/iterator/TIntIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for int collections. + */ +public interface TIntIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next int in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public int next(); +} diff --git a/src/gnu/trove/iterator/TIntLongIterator.java b/src/gnu/trove/iterator/TIntLongIterator.java new file mode 100644 index 0000000..f0e7abb --- /dev/null +++ b/src/gnu/trove/iterator/TIntLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TIntObjectIterator.java b/src/gnu/trove/iterator/TIntObjectIterator.java new file mode 100644 index 0000000..8de94ff --- /dev/null +++ b/src/gnu/trove/iterator/TIntObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TIntObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TIntObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TIntObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TIntObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TIntObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TIntShortIterator.java b/src/gnu/trove/iterator/TIntShortIterator.java new file mode 100644 index 0000000..63b83fa --- /dev/null +++ b/src/gnu/trove/iterator/TIntShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TIterator.java b/src/gnu/trove/iterator/TIterator.java new file mode 100644 index 0000000..a5459e2 --- /dev/null +++ b/src/gnu/trove/iterator/TIterator.java @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// +package gnu.trove.iterator; + +/** + * Common interface for all iterators used in Trove. + */ +public interface TIterator { + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + public boolean hasNext(); + + /** + * Removes the last entry returned by the iterator. The result of invoking this + * method more than once for a single entry is undefined and can leave the + * underlying data structure in a confused state. + */ + public void remove(); +} diff --git a/src/gnu/trove/iterator/TLongByteIterator.java b/src/gnu/trove/iterator/TLongByteIterator.java new file mode 100644 index 0000000..3b6a360 --- /dev/null +++ b/src/gnu/trove/iterator/TLongByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TLongCharIterator.java b/src/gnu/trove/iterator/TLongCharIterator.java new file mode 100644 index 0000000..2a4180a --- /dev/null +++ b/src/gnu/trove/iterator/TLongCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TLongDoubleIterator.java b/src/gnu/trove/iterator/TLongDoubleIterator.java new file mode 100644 index 0000000..c314a93 --- /dev/null +++ b/src/gnu/trove/iterator/TLongDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TLongFloatIterator.java b/src/gnu/trove/iterator/TLongFloatIterator.java new file mode 100644 index 0000000..87fd8a3 --- /dev/null +++ b/src/gnu/trove/iterator/TLongFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TLongIntIterator.java b/src/gnu/trove/iterator/TLongIntIterator.java new file mode 100644 index 0000000..75877c7 --- /dev/null +++ b/src/gnu/trove/iterator/TLongIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TLongIterator.java b/src/gnu/trove/iterator/TLongIterator.java new file mode 100644 index 0000000..60e7cb9 --- /dev/null +++ b/src/gnu/trove/iterator/TLongIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for long collections. + */ +public interface TLongIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next long in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public long next(); +} diff --git a/src/gnu/trove/iterator/TLongLongIterator.java b/src/gnu/trove/iterator/TLongLongIterator.java new file mode 100644 index 0000000..badf4d6 --- /dev/null +++ b/src/gnu/trove/iterator/TLongLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TLongObjectIterator.java b/src/gnu/trove/iterator/TLongObjectIterator.java new file mode 100644 index 0000000..08566bb --- /dev/null +++ b/src/gnu/trove/iterator/TLongObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TLongObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TLongObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TLongObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TLongObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TLongObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TLongShortIterator.java b/src/gnu/trove/iterator/TLongShortIterator.java new file mode 100644 index 0000000..71ebc5a --- /dev/null +++ b/src/gnu/trove/iterator/TLongShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TObjectByteIterator.java b/src/gnu/trove/iterator/TObjectByteIterator.java new file mode 100644 index 0000000..6fa4fc5 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectByteIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and byte. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectByteIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectByteIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectByteIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectByteIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TObjectCharIterator.java b/src/gnu/trove/iterator/TObjectCharIterator.java new file mode 100644 index 0000000..9728116 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectCharIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and char. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectCharIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectCharIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectCharIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectCharIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TObjectDoubleIterator.java b/src/gnu/trove/iterator/TObjectDoubleIterator.java new file mode 100644 index 0000000..1833cb3 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectDoubleIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and double. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectDoubleIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectDoubleIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectDoubleIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectDoubleIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TObjectFloatIterator.java b/src/gnu/trove/iterator/TObjectFloatIterator.java new file mode 100644 index 0000000..fb735e4 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectFloatIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and float. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectFloatIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectFloatIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectFloatIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectFloatIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TObjectIntIterator.java b/src/gnu/trove/iterator/TObjectIntIterator.java new file mode 100644 index 0000000..98a45be --- /dev/null +++ b/src/gnu/trove/iterator/TObjectIntIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and int. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectIntIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectIntIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectIntIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectIntIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TObjectLongIterator.java b/src/gnu/trove/iterator/TObjectLongIterator.java new file mode 100644 index 0000000..c882a2e --- /dev/null +++ b/src/gnu/trove/iterator/TObjectLongIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and long. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectLongIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectLongIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectLongIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectLongIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TObjectShortIterator.java b/src/gnu/trove/iterator/TObjectShortIterator.java new file mode 100644 index 0000000..11b5066 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectShortIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and short. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectShortIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectShortIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectShortIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectShortIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TPrimitiveIterator.java b/src/gnu/trove/iterator/TPrimitiveIterator.java new file mode 100644 index 0000000..1511bcd --- /dev/null +++ b/src/gnu/trove/iterator/TPrimitiveIterator.java @@ -0,0 +1,63 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +/** + * Implements all iterator functions for the hashed object set. Subclasses may + * override objectAtIndex to vary the object returned by calls to next() (e.g. + * for values, and Map.Entry objects). + *

+ *

+ * Note that iteration is fastest if you forego the calls to hasNext in + * favor of checking the size of the structure yourself and then call next() + * that many times: + *

+ * + *

+ * Iterator i = collection.iterator();
+ * for (int size = collection.size(); size-- > 0;) {
+ * 	Object o = i.next();
+ * }
+ * 
+ *

+ *

+ * You may, of course, use the hasNext(), next() idiom too if you aren't in a + * performance critical spot. + *

+ */ +public interface TPrimitiveIterator extends TIterator { + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext(); + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove(); + +} // TPrimitiveIterator diff --git a/src/gnu/trove/iterator/TShortByteIterator.java b/src/gnu/trove/iterator/TShortByteIterator.java new file mode 100644 index 0000000..31a1314 --- /dev/null +++ b/src/gnu/trove/iterator/TShortByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TShortCharIterator.java b/src/gnu/trove/iterator/TShortCharIterator.java new file mode 100644 index 0000000..a2a72e4 --- /dev/null +++ b/src/gnu/trove/iterator/TShortCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TShortDoubleIterator.java b/src/gnu/trove/iterator/TShortDoubleIterator.java new file mode 100644 index 0000000..0702365 --- /dev/null +++ b/src/gnu/trove/iterator/TShortDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TShortFloatIterator.java b/src/gnu/trove/iterator/TShortFloatIterator.java new file mode 100644 index 0000000..cd7fc60 --- /dev/null +++ b/src/gnu/trove/iterator/TShortFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TShortIntIterator.java b/src/gnu/trove/iterator/TShortIntIterator.java new file mode 100644 index 0000000..5ff0dba --- /dev/null +++ b/src/gnu/trove/iterator/TShortIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TShortIterator.java b/src/gnu/trove/iterator/TShortIterator.java new file mode 100644 index 0000000..f998d8b --- /dev/null +++ b/src/gnu/trove/iterator/TShortIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for short collections. + */ +public interface TShortIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next short in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public short next(); +} diff --git a/src/gnu/trove/iterator/TShortLongIterator.java b/src/gnu/trove/iterator/TShortLongIterator.java new file mode 100644 index 0000000..e43e2dc --- /dev/null +++ b/src/gnu/trove/iterator/TShortLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TShortObjectIterator.java b/src/gnu/trove/iterator/TShortObjectIterator.java new file mode 100644 index 0000000..4e3f8a3 --- /dev/null +++ b/src/gnu/trove/iterator/TShortObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TShortObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TShortObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TShortObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TShortObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TShortObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TShortShortIterator.java b/src/gnu/trove/iterator/TShortShortIterator.java new file mode 100644 index 0000000..3984f2c --- /dev/null +++ b/src/gnu/trove/iterator/TShortShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/hash/TObjectHashIterator.java b/src/gnu/trove/iterator/hash/TObjectHashIterator.java new file mode 100644 index 0000000..8a8ef1b --- /dev/null +++ b/src/gnu/trove/iterator/hash/TObjectHashIterator.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator.hash; + +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.impl.hash.THashIterator; + +/** + * Iterator for hashtables that use open addressing to resolve collisions. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: TObjectHashIterator.java,v 1.1.2.4 2009/10/09 01:44:34 robeden + * Exp $ + */ + +public class TObjectHashIterator extends THashIterator { + + protected final TObjectHash _objectHash; + + public TObjectHashIterator(TObjectHash hash) { + super(hash); + _objectHash = hash; + } + + @Override + @SuppressWarnings("unchecked") + protected E objectAtIndex(int index) { + Object obj = _objectHash._set[index]; + if (obj == TObjectHash.FREE || obj == TObjectHash.REMOVED) { + return null; + } + return (E) obj; + } + +} // TObjectHashIterator diff --git a/src/gnu/trove/list/TByteList.java b/src/gnu/trove/list/TByteList.java new file mode 100644 index 0000000..a33758e --- /dev/null +++ b/src/gnu/trove/list/TByteList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TByteCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TByteList extends TByteCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public byte getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an byte value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(byte val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an byte[] value + */ + public void add(byte[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an byte[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(byte[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an byte value + */ + public void insert(int offset, byte value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an byte[] value + */ + public void insert(int offset, byte[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an byte[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, byte[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an byte value + */ + public byte get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an byte value + * + * @return The value previously at the given index. + */ + public byte set(int offset, byte val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, byte[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, byte[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an byte value + * @return the value previously stored at offset. + */ + public byte replace(int offset, byte val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an byte value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(byte value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an byte that is the value removed. + */ + public byte removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TByteList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an byte[] value + */ + @Override + public byte[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an byte[] value + */ + public byte[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public byte[] toArray(byte[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public byte[] toArray(byte[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TByteProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TByteProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TByteProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TByteProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(byte val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, byte val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(byte value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(byte value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an byte value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(byte value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an byte value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, byte value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an byte value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(byte value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an byte value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, byte value); + + /** + * Searches the list for value + * + * @param value + * an byte value + * @return true if value is in the list. + */ + @Override + public boolean contains(byte value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TByteList grep(TByteProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TByteList inverseGrep(TByteProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public byte max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public byte min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public byte sum(); +} diff --git a/src/gnu/trove/list/TCharList.java b/src/gnu/trove/list/TCharList.java new file mode 100644 index 0000000..029df0c --- /dev/null +++ b/src/gnu/trove/list/TCharList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TCharCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TCharList extends TCharCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public char getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an char value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(char val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an char[] value + */ + public void add(char[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an char[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(char[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an char value + */ + public void insert(int offset, char value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an char[] value + */ + public void insert(int offset, char[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an char[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, char[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an char value + */ + public char get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an char value + * + * @return The value previously at the given index. + */ + public char set(int offset, char val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, char[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, char[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an char value + * @return the value previously stored at offset. + */ + public char replace(int offset, char val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an char value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(char value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an char that is the value removed. + */ + public char removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TCharList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an char[] value + */ + @Override + public char[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an char[] value + */ + public char[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public char[] toArray(char[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public char[] toArray(char[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TCharProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TCharProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TCharProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TCharProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(char val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, char val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(char value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(char value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an char value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(char value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an char value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, char value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an char value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(char value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an char value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, char value); + + /** + * Searches the list for value + * + * @param value + * an char value + * @return true if value is in the list. + */ + @Override + public boolean contains(char value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TCharList grep(TCharProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TCharList inverseGrep(TCharProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public char max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public char min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public char sum(); +} diff --git a/src/gnu/trove/list/TDoubleList.java b/src/gnu/trove/list/TDoubleList.java new file mode 100644 index 0000000..36abeb8 --- /dev/null +++ b/src/gnu/trove/list/TDoubleList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TDoubleCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TDoubleList extends TDoubleCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public double getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an double value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(double val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an double[] value + */ + public void add(double[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an double[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(double[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an double value + */ + public void insert(int offset, double value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an double[] value + */ + public void insert(int offset, double[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an double[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, double[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an double value + */ + public double get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an double value + * + * @return The value previously at the given index. + */ + public double set(int offset, double val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, double[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, double[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an double value + * @return the value previously stored at offset. + */ + public double replace(int offset, double val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an double value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(double value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an double that is the value removed. + */ + public double removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TDoubleList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an double[] value + */ + @Override + public double[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an double[] value + */ + public double[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public double[] toArray(double[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public double[] toArray(double[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TDoubleProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TDoubleProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TDoubleProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TDoubleProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(double val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, double val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(double value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(double value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an double value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(double value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an double value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, double value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an double value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(double value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an double value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, double value); + + /** + * Searches the list for value + * + * @param value + * an double value + * @return true if value is in the list. + */ + @Override + public boolean contains(double value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TDoubleList grep(TDoubleProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TDoubleList inverseGrep(TDoubleProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public double max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public double min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public double sum(); +} diff --git a/src/gnu/trove/list/TFloatList.java b/src/gnu/trove/list/TFloatList.java new file mode 100644 index 0000000..9dcbe91 --- /dev/null +++ b/src/gnu/trove/list/TFloatList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TFloatCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TFloatList extends TFloatCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public float getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an float value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(float val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an float[] value + */ + public void add(float[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an float[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(float[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an float value + */ + public void insert(int offset, float value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an float[] value + */ + public void insert(int offset, float[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an float[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, float[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an float value + */ + public float get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an float value + * + * @return The value previously at the given index. + */ + public float set(int offset, float val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, float[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, float[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an float value + * @return the value previously stored at offset. + */ + public float replace(int offset, float val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an float value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(float value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an float that is the value removed. + */ + public float removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TFloatList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an float[] value + */ + @Override + public float[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an float[] value + */ + public float[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public float[] toArray(float[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public float[] toArray(float[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TFloatProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TFloatProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TFloatProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TFloatProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(float val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, float val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(float value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(float value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an float value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(float value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an float value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, float value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an float value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(float value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an float value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, float value); + + /** + * Searches the list for value + * + * @param value + * an float value + * @return true if value is in the list. + */ + @Override + public boolean contains(float value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TFloatList grep(TFloatProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TFloatList inverseGrep(TFloatProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public float max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public float min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public float sum(); +} diff --git a/src/gnu/trove/list/TIntList.java b/src/gnu/trove/list/TIntList.java new file mode 100644 index 0000000..afb3e0c --- /dev/null +++ b/src/gnu/trove/list/TIntList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TIntCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TIntList extends TIntCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public int getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an int value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(int val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an int[] value + */ + public void add(int[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an int[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(int[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an int value + */ + public void insert(int offset, int value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an int[] value + */ + public void insert(int offset, int[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an int[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, int[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an int value + */ + public int get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an int value + * + * @return The value previously at the given index. + */ + public int set(int offset, int val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, int[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, int[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an int value + * @return the value previously stored at offset. + */ + public int replace(int offset, int val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an int value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(int value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an int that is the value removed. + */ + public int removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TIntList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an int[] value + */ + @Override + public int[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an int[] value + */ + public int[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public int[] toArray(int[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public int[] toArray(int[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TIntProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TIntProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TIntProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TIntProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(int val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, int val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(int value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(int value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an int value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an int value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, int value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an int value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an int value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, int value); + + /** + * Searches the list for value + * + * @param value + * an int value + * @return true if value is in the list. + */ + @Override + public boolean contains(int value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TIntList grep(TIntProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TIntList inverseGrep(TIntProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public int max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public int min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public int sum(); +} diff --git a/src/gnu/trove/list/TLinkable.java b/src/gnu/trove/list/TLinkable.java new file mode 100644 index 0000000..7e80727 --- /dev/null +++ b/src/gnu/trove/list/TLinkable.java @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +import java.io.Serializable; + +/** + * Interface for Objects which can be inserted into a TLinkedList. + * + * @author Eric D. Friedman + * @version $Id: TLinkable.java,v 1.1.2.2 2009/09/04 12:32:33 upholderoftruth + * Exp $ + * @see gnu.trove.list.linked.TLinkedList + */ + +public interface TLinkable extends Serializable { + static final long serialVersionUID = 997545054865482562L; + + /** + * Returns the linked list node after this one. + * + * @return a TLinkable value + */ + public T getNext(); + + /** + * Returns the linked list node before this one. + * + * @return a TLinkable value + */ + public T getPrevious(); + + /** + * Sets the linked list node after this one. + * + * @param linkable + * a TLinkable value + */ + public void setNext(T linkable); + + /** + * Sets the linked list node before this one. + * + * @param linkable + * a TLinkable value + */ + public void setPrevious(T linkable); +}// TLinkable diff --git a/src/gnu/trove/list/TLinkableAdapter.java b/src/gnu/trove/list/TLinkableAdapter.java new file mode 100644 index 0000000..9fd3f12 --- /dev/null +++ b/src/gnu/trove/list/TLinkableAdapter.java @@ -0,0 +1,44 @@ +package gnu.trove.list; + +/** + * Simple adapter class implementing {@link TLinkable}, so you don't have to. + * Example: + * + *

+ * private class MyObject extends TLinkableAdapter {
+ * 	private final String value;
+ * 
+ * 	MyObject(String value) {
+ * 		this.value = value;
+ * 	}
+ * 
+ * 	public String getValue() {
+ * 		return value;
+ * 	}
+ * }
+ * 
+ */ +public abstract class TLinkableAdapter implements TLinkable { + private volatile T next; + private volatile T prev; + + @Override + public T getNext() { + return next; + } + + @Override + public void setNext(T next) { + this.next = next; + } + + @Override + public T getPrevious() { + return prev; + } + + @Override + public void setPrevious(T prev) { + this.prev = prev; + } +} diff --git a/src/gnu/trove/list/TLongList.java b/src/gnu/trove/list/TLongList.java new file mode 100644 index 0000000..9333445 --- /dev/null +++ b/src/gnu/trove/list/TLongList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TLongCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TLongList extends TLongCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public long getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an long value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(long val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an long[] value + */ + public void add(long[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an long[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(long[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an long value + */ + public void insert(int offset, long value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an long[] value + */ + public void insert(int offset, long[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an long[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, long[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an long value + */ + public long get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an long value + * + * @return The value previously at the given index. + */ + public long set(int offset, long val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, long[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, long[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an long value + * @return the value previously stored at offset. + */ + public long replace(int offset, long val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an long value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(long value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an long that is the value removed. + */ + public long removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TLongList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an long[] value + */ + @Override + public long[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an long[] value + */ + public long[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public long[] toArray(long[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public long[] toArray(long[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TLongProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TLongProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TLongProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TLongProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(long val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, long val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(long value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(long value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an long value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(long value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an long value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, long value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an long value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(long value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an long value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, long value); + + /** + * Searches the list for value + * + * @param value + * an long value + * @return true if value is in the list. + */ + @Override + public boolean contains(long value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TLongList grep(TLongProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TLongList inverseGrep(TLongProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public long max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public long min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public long sum(); +} diff --git a/src/gnu/trove/list/TShortList.java b/src/gnu/trove/list/TShortList.java new file mode 100644 index 0000000..46d87bb --- /dev/null +++ b/src/gnu/trove/list/TShortList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TShortCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TShortList extends TShortCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public short getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an short value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(short val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an short[] value + */ + public void add(short[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an short[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(short[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an short value + */ + public void insert(int offset, short value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an short[] value + */ + public void insert(int offset, short[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an short[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, short[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an short value + */ + public short get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an short value + * + * @return The value previously at the given index. + */ + public short set(int offset, short val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, short[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, short[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an short value + * @return the value previously stored at offset. + */ + public short replace(int offset, short val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an short value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(short value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an short that is the value removed. + */ + public short removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TShortList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an short[] value + */ + @Override + public short[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an short[] value + */ + public short[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public short[] toArray(short[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public short[] toArray(short[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TShortProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TShortProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TShortProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TShortProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(short val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, short val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(short value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(short value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an short value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(short value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an short value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, short value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an short value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(short value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an short value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, short value); + + /** + * Searches the list for value + * + * @param value + * an short value + * @return true if value is in the list. + */ + @Override + public boolean contains(short value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TShortList grep(TShortProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TShortList inverseGrep(TShortProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public short max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public short min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public short sum(); +} diff --git a/src/gnu/trove/list/array/TByteArrayList.java b/src/gnu/trove/list/array/TByteArrayList.java new file mode 100644 index 0000000..43832a6 --- /dev/null +++ b/src/gnu/trove/list/array/TByteArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TByteFunction; +import gnu.trove.list.TByteList; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.TByteCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of byte primitives. + */ +public class TByteArrayList implements TByteList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected byte[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the byte value that represents null */ + protected byte no_entry_value; + + /** + * Creates a new TByteArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TByteArrayList() { + this(DEFAULT_CAPACITY, (byte) 0); + } + + /** + * Creates a new TByteArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TByteArrayList(int capacity) { + this(capacity, (byte) 0); + } + + /** + * Creates a new TByteArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an byte value that represents null. + */ + public TByteArrayList(int capacity, byte no_entry_value) { + _data = new byte[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TByteArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TByteArrayList(TByteCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TByteArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an byte[] value + */ + public TByteArrayList(byte[] values) { + this(values.length); + add(values); + } + + protected TByteArrayList(byte[] values, byte no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TByteArrayList wrap(byte[] values) { + return wrap(values, (byte) 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TByteArrayList wrap(byte[] values, byte no_entry_value) { + return new TByteArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + byte[] tmp = new byte[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + byte[] tmp = new byte[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(byte val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public byte get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public byte getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public byte set(int offset, byte val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + byte prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public byte replace(int offset, byte val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + byte old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, byte val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new byte[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public byte removeAt(int offset) { + byte old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + if (this == collection) { + return true; + } + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Byte element : collection) { + byte e = element.byteValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + boolean changed = false; + for (byte element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + byte tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TByteList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TByteArrayList list = new TByteArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(int offset, int len) { + byte[] rv = new byte[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TByteList)) + return false; + + if (other instanceof TByteArrayList) { + TByteArrayList that = (TByteArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TByteList that = (TByteList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TByteProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(byte val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, byte val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + byte midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(byte value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, byte value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(byte value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, byte value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TByteList grep(TByteProcedure condition) { + TByteArrayList list = new TByteArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TByteList inverseGrep(TByteProcedure condition) { + TByteArrayList list = new TByteArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public byte max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + byte max = Byte.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public byte min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + byte min = Byte.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public byte sum() { + byte sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TByteArrayList iterator */ + class TByteArrayIterator implements TByteIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TByteArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + try { + byte next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TByteArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeByte(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // ENTRIES + int len = in.readInt(); + _data = new byte[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readByte(); + } + } +} // TByteArrayList diff --git a/src/gnu/trove/list/array/TCharArrayList.java b/src/gnu/trove/list/array/TCharArrayList.java new file mode 100644 index 0000000..47a0606 --- /dev/null +++ b/src/gnu/trove/list/array/TCharArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TCharFunction; +import gnu.trove.list.TCharList; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.TCharCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of char primitives. + */ +public class TCharArrayList implements TCharList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected char[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the char value that represents null */ + protected char no_entry_value; + + /** + * Creates a new TCharArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TCharArrayList() { + this(DEFAULT_CAPACITY, (char) 0); + } + + /** + * Creates a new TCharArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TCharArrayList(int capacity) { + this(capacity, (char) 0); + } + + /** + * Creates a new TCharArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an char value that represents null. + */ + public TCharArrayList(int capacity, char no_entry_value) { + _data = new char[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TCharArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TCharArrayList(TCharCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TCharArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an char[] value + */ + public TCharArrayList(char[] values) { + this(values.length); + add(values); + } + + protected TCharArrayList(char[] values, char no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TCharArrayList wrap(char[] values) { + return wrap(values, (char) 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TCharArrayList wrap(char[] values, char no_entry_value) { + return new TCharArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + char[] tmp = new char[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + char[] tmp = new char[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(char val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public char get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public char getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public char set(int offset, char val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + char prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public char replace(int offset, char val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + char old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, char val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new char[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public char removeAt(int offset) { + char old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + if (this == collection) { + return true; + } + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Character element : collection) { + char e = element.charValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + boolean changed = false; + for (char element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + char tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TCharList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TCharArrayList list = new TCharArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(int offset, int len) { + char[] rv = new char[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TCharList)) + return false; + + if (other instanceof TCharArrayList) { + TCharArrayList that = (TCharArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TCharList that = (TCharList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TCharProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(char val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, char val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + char midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(char value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, char value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(char value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, char value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TCharList grep(TCharProcedure condition) { + TCharArrayList list = new TCharArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TCharList inverseGrep(TCharProcedure condition) { + TCharArrayList list = new TCharArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public char max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + char max = Character.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public char min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + char min = Character.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public char sum() { + char sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TCharArrayList iterator */ + class TCharArrayIterator implements TCharIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TCharArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public char next() { + try { + char next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TCharArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeChar(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // ENTRIES + int len = in.readInt(); + _data = new char[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readChar(); + } + } +} // TCharArrayList diff --git a/src/gnu/trove/list/array/TDoubleArrayList.java b/src/gnu/trove/list/array/TDoubleArrayList.java new file mode 100644 index 0000000..8720cb0 --- /dev/null +++ b/src/gnu/trove/list/array/TDoubleArrayList.java @@ -0,0 +1,1073 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TDoubleFunction; +import gnu.trove.list.TDoubleList; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.TDoubleCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of double primitives. + */ +public class TDoubleArrayList implements TDoubleList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected double[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the double value that represents null */ + protected double no_entry_value; + + /** + * Creates a new TDoubleArrayList instance with the default + * capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TDoubleArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TDoubleArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TDoubleArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TDoubleArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an double value that represents null. + */ + public TDoubleArrayList(int capacity, double no_entry_value) { + _data = new double[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TDoubleArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TDoubleArrayList(TDoubleCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TDoubleArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an double[] value + */ + public TDoubleArrayList(double[] values) { + this(values.length); + add(values); + } + + protected TDoubleArrayList(double[] values, double no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TDoubleArrayList wrap(double[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TDoubleArrayList wrap(double[] values, double no_entry_value) { + return new TDoubleArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + double[] tmp = new double[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + double[] tmp = new double[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(double val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public double get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public double getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public double set(int offset, double val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + double prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public double replace(int offset, double val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + double old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, double val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new double[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public double removeAt(int offset) { + double old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + if (this == collection) { + return true; + } + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Double element : collection) { + double e = element.doubleValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + boolean changed = false; + for (double element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + double tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TDoubleList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TDoubleArrayList list = new TDoubleArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(int offset, int len) { + double[] rv = new double[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TDoubleList)) + return false; + + if (other instanceof TDoubleArrayList) { + TDoubleArrayList that = (TDoubleArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TDoubleList that = (TDoubleList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(double val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, double val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + double midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(double value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, double value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(double value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, double value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList grep(TDoubleProcedure condition) { + TDoubleArrayList list = new TDoubleArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + TDoubleArrayList list = new TDoubleArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public double max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + double max = Double.NEGATIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public double min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + double min = Double.POSITIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public double sum() { + double sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TDoubleArrayList iterator */ + class TDoubleArrayIterator implements TDoubleIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TDoubleArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public double next() { + try { + double next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TDoubleArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeDouble(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // ENTRIES + int len = in.readInt(); + _data = new double[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readDouble(); + } + } +} // TDoubleArrayList diff --git a/src/gnu/trove/list/array/TFloatArrayList.java b/src/gnu/trove/list/array/TFloatArrayList.java new file mode 100644 index 0000000..ba671e3 --- /dev/null +++ b/src/gnu/trove/list/array/TFloatArrayList.java @@ -0,0 +1,1073 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TFloatFunction; +import gnu.trove.list.TFloatList; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.TFloatCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of float primitives. + */ +public class TFloatArrayList implements TFloatList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected float[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the float value that represents null */ + protected float no_entry_value; + + /** + * Creates a new TFloatArrayList instance with the default + * capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TFloatArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TFloatArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TFloatArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TFloatArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an float value that represents null. + */ + public TFloatArrayList(int capacity, float no_entry_value) { + _data = new float[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TFloatArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TFloatArrayList(TFloatCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TFloatArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an float[] value + */ + public TFloatArrayList(float[] values) { + this(values.length); + add(values); + } + + protected TFloatArrayList(float[] values, float no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TFloatArrayList wrap(float[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TFloatArrayList wrap(float[] values, float no_entry_value) { + return new TFloatArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + float[] tmp = new float[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + float[] tmp = new float[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(float val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public float get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public float getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public float set(int offset, float val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + float prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public float replace(int offset, float val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + float old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, float val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new float[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public float removeAt(int offset) { + float old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + if (this == collection) { + return true; + } + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Float element : collection) { + float e = element.floatValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + boolean changed = false; + for (float element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + float tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TFloatList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TFloatArrayList list = new TFloatArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(int offset, int len) { + float[] rv = new float[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TFloatList)) + return false; + + if (other instanceof TFloatArrayList) { + TFloatArrayList that = (TFloatArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TFloatList that = (TFloatList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(float val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, float val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + float midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(float value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, float value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(float value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, float value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TFloatList grep(TFloatProcedure condition) { + TFloatArrayList list = new TFloatArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + TFloatArrayList list = new TFloatArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public float max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + float max = Float.NEGATIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public float min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + float min = Float.POSITIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public float sum() { + float sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TFloatArrayList iterator */ + class TFloatArrayIterator implements TFloatIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TFloatArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public float next() { + try { + float next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TFloatArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeFloat(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // ENTRIES + int len = in.readInt(); + _data = new float[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readFloat(); + } + } +} // TFloatArrayList diff --git a/src/gnu/trove/list/array/TIntArrayList.java b/src/gnu/trove/list/array/TIntArrayList.java new file mode 100644 index 0000000..9a07c33 --- /dev/null +++ b/src/gnu/trove/list/array/TIntArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TIntFunction; +import gnu.trove.list.TIntList; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.TIntCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of int primitives. + */ +public class TIntArrayList implements TIntList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected int[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the int value that represents null */ + protected int no_entry_value; + + /** + * Creates a new TIntArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TIntArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TIntArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TIntArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TIntArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an int value that represents null. + */ + public TIntArrayList(int capacity, int no_entry_value) { + _data = new int[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TIntArrayList instance that contains a copy of the + * collection passed to us. + * + * @param collection + * the collection to copy + */ + public TIntArrayList(TIntCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TIntArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an int[] value + */ + public TIntArrayList(int[] values) { + this(values.length); + add(values); + } + + protected TIntArrayList(int[] values, int no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TIntArrayList wrap(int[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TIntArrayList wrap(int[] values, int no_entry_value) { + return new TIntArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + int[] tmp = new int[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + int[] tmp = new int[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(int val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public int get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public int getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public int set(int offset, int val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + int prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public int replace(int offset, int val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + int old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, int val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new int[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public int removeAt(int offset) { + int old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + if (this == collection) { + return true; + } + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Integer element : collection) { + int e = element.intValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + boolean changed = false; + for (int element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + int tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TIntList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TIntArrayList list = new TIntArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int offset, int len) { + int[] rv = new int[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TIntList)) + return false; + + if (other instanceof TIntArrayList) { + TIntArrayList that = (TIntArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TIntList that = (TIntList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TIntProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(int val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, int val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + int midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, int value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, int value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TIntList grep(TIntProcedure condition) { + TIntArrayList list = new TIntArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TIntList inverseGrep(TIntProcedure condition) { + TIntArrayList list = new TIntArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public int max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + int max = Integer.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public int min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + int min = Integer.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public int sum() { + int sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TIntArrayList iterator */ + class TIntArrayIterator implements TIntIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TIntArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public int next() { + try { + int next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TIntArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeInt(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // ENTRIES + int len = in.readInt(); + _data = new int[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readInt(); + } + } +} // TIntArrayList diff --git a/src/gnu/trove/list/array/TLongArrayList.java b/src/gnu/trove/list/array/TLongArrayList.java new file mode 100644 index 0000000..2379262 --- /dev/null +++ b/src/gnu/trove/list/array/TLongArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TLongFunction; +import gnu.trove.list.TLongList; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.TLongCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of long primitives. + */ +public class TLongArrayList implements TLongList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected long[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the long value that represents null */ + protected long no_entry_value; + + /** + * Creates a new TLongArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TLongArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TLongArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TLongArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TLongArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an long value that represents null. + */ + public TLongArrayList(int capacity, long no_entry_value) { + _data = new long[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TLongArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TLongArrayList(TLongCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TLongArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an long[] value + */ + public TLongArrayList(long[] values) { + this(values.length); + add(values); + } + + protected TLongArrayList(long[] values, long no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TLongArrayList wrap(long[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TLongArrayList wrap(long[] values, long no_entry_value) { + return new TLongArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + long[] tmp = new long[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + long[] tmp = new long[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(long val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public long get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public long getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public long set(int offset, long val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + long prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public long replace(int offset, long val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + long old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, long val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new long[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public long removeAt(int offset) { + long old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + if (this == collection) { + return true; + } + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Long element : collection) { + long e = element.longValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + boolean changed = false; + for (long element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + long tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TLongList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TLongArrayList list = new TLongArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(int offset, int len) { + long[] rv = new long[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TLongList)) + return false; + + if (other instanceof TLongArrayList) { + TLongArrayList that = (TLongArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TLongList that = (TLongList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TLongProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(long val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, long val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + long midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(long value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, long value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(long value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, long value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TLongList grep(TLongProcedure condition) { + TLongArrayList list = new TLongArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TLongList inverseGrep(TLongProcedure condition) { + TLongArrayList list = new TLongArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public long max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + long max = Long.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public long min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + long min = Long.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public long sum() { + long sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TLongArrayList iterator */ + class TLongArrayIterator implements TLongIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TLongArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public long next() { + try { + long next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TLongArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeLong(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // ENTRIES + int len = in.readInt(); + _data = new long[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readLong(); + } + } +} // TLongArrayList diff --git a/src/gnu/trove/list/array/TShortArrayList.java b/src/gnu/trove/list/array/TShortArrayList.java new file mode 100644 index 0000000..1309942 --- /dev/null +++ b/src/gnu/trove/list/array/TShortArrayList.java @@ -0,0 +1,1073 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TShortFunction; +import gnu.trove.list.TShortList; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.TShortCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of short primitives. + */ +public class TShortArrayList implements TShortList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected short[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the short value that represents null */ + protected short no_entry_value; + + /** + * Creates a new TShortArrayList instance with the default + * capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TShortArrayList() { + this(DEFAULT_CAPACITY, (short) 0); + } + + /** + * Creates a new TShortArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TShortArrayList(int capacity) { + this(capacity, (short) 0); + } + + /** + * Creates a new TShortArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an short value that represents null. + */ + public TShortArrayList(int capacity, short no_entry_value) { + _data = new short[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TShortArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TShortArrayList(TShortCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TShortArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an short[] value + */ + public TShortArrayList(short[] values) { + this(values.length); + add(values); + } + + protected TShortArrayList(short[] values, short no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TShortArrayList wrap(short[] values) { + return wrap(values, (short) 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TShortArrayList wrap(short[] values, short no_entry_value) { + return new TShortArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + short[] tmp = new short[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + short[] tmp = new short[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(short val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public short get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public short getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public short set(int offset, short val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + short prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public short replace(int offset, short val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + short old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, short val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new short[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public short removeAt(int offset) { + short old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + if (this == collection) { + return true; + } + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Short element : collection) { + short e = element.shortValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + boolean changed = false; + for (short element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + short tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TShortList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TShortArrayList list = new TShortArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(int offset, int len) { + short[] rv = new short[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TShortList)) + return false; + + if (other instanceof TShortArrayList) { + TShortArrayList that = (TShortArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TShortList that = (TShortList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TShortProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(short val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, short val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + short midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(short value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, short value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(short value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, short value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TShortList grep(TShortProcedure condition) { + TShortArrayList list = new TShortArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TShortList inverseGrep(TShortProcedure condition) { + TShortArrayList list = new TShortArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public short max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + short max = Short.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public short min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + short min = Short.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public short sum() { + short sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TShortArrayList iterator */ + class TShortArrayIterator implements TShortIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TShortArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public short next() { + try { + short next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TShortArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeShort(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // ENTRIES + int len = in.readInt(); + _data = new short[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readShort(); + } + } +} // TShortArrayList diff --git a/src/gnu/trove/list/linked/TByteLinkedList.java b/src/gnu/trove/list/linked/TByteLinkedList.java new file mode 100644 index 0000000..b45f0ec --- /dev/null +++ b/src/gnu/trove/list/linked/TByteLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TByteFunction; +import gnu.trove.list.TByteList; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.TByteCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of byte primitives. + */ +public class TByteLinkedList implements TByteList, Externalizable { + private byte no_entry_value; + private int size; + + private TByteLink head = null; + private TByteLink tail = head; + + public TByteLinkedList() { + this(Constants.DEFAULT_BYTE_NO_ENTRY_VALUE); + } + + public TByteLinkedList(byte no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TByteLinkedList(TByteList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TByteIterator iterator = list.iterator(); iterator.hasNext();) { + byte next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(byte val) { + TByteLink l = new TByteLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals) { + for (byte val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + byte val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte value) { + TByteLinkedList tmp = new TByteLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TByteLinkedList tmp) { + TByteLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TByteLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TByteLinkedList link(byte[] values, int valOffset, int len) { + TByteLinkedList ret = new TByteLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TByteLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TByteLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TByteLink getLink(TByteLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TByteLink getLink(TByteLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public byte set(int offset, byte val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TByteLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + byte prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + byte value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public byte replace(int offset, byte val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte value) { + boolean changed = false; + for (TByteLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TByteLink from the list + * + * @param l + */ + private void removeLink(TByteLink l) { + if (no(l)) + return; + + size--; + + TByteLink prev = l.getPrevious(); + TByteLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Byte) { + Byte i = (Byte) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + if (isEmpty()) + return false; + + for (TByteIterator it = collection.iterator(); it.hasNext();) { + byte i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + if (isEmpty()) + return false; + + for (byte i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Byte v : collection) { + if (add(v.byteValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + boolean ret = false; + for (TByteIterator it = collection.iterator(); it.hasNext();) { + byte i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + boolean ret = false; + for (byte i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + Arrays.sort(array); + + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + Arrays.sort(array); + + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public byte removeAt(int offset) { + TByteLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + byte prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + for (TByteLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TByteLink h = head; + TByteLink t = tail; + TByteLink prev, next, tmp; + + // + TByteLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TByteLink start = getLinkAt(from); + TByteLink stop = getLinkAt(to); + TByteLink prev, next; + TByteLink tmp = null; + + TByteLink tmpHead = start.getPrevious(); + + // + TByteLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TByteLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TByteList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TByteLinkedList ret = new TByteLinkedList(); + TByteLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return toArray(new byte[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(int offset, int len) { + return toArray(new byte[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TByteLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + for (TByteLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TByteProcedure procedure) { + for (TByteLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TByteList tmp = subList(fromIndex, toIndex); + byte[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(byte val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, byte val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TByteLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TByteLink middle; + int mid; + int from = fromIndex; + TByteLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(byte value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, byte value) { + int count = offset; + + TByteLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(byte value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, byte value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TByteLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte value) { + if (isEmpty()) + return false; + + for (TByteLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteIterator() { + TByteLink l = head; + TByteLink current; + + @Override + public byte next() { + if (no(l)) + throw new NoSuchElementException(); + + byte ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TByteList grep(TByteProcedure condition) { + TByteList ret = new TByteLinkedList(); + for (TByteLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TByteList inverseGrep(TByteProcedure condition) { + TByteList ret = new TByteLinkedList(); + for (TByteLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte max() { + byte ret = Byte.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TByteLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte min() { + byte ret = Byte.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TByteLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte sum() { + byte sum = 0; + + for (TByteLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TByteLink { + byte value; + TByteLink previous; + TByteLink next; + + TByteLink(byte value) { + this.value = value; + } + + public byte getValue() { + return value; + } + + public void setValue(byte value) { + this.value = value; + } + + public TByteLink getPrevious() { + return previous; + } + + public void setPrevious(TByteLink previous) { + this.previous = previous; + } + + public TByteLink getNext() { + return next; + } + + public void setNext(TByteLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TByteProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(byte value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TByteIterator iterator = iterator(); iterator.hasNext();) { + byte next = iterator.next(); + out.writeByte(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readByte()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TByteList)) + return false; + + TByteList that = (TByteList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TByteIterator it = iterator(); + while (it.hasNext()) { + byte next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TByteLinkedList diff --git a/src/gnu/trove/list/linked/TCharLinkedList.java b/src/gnu/trove/list/linked/TCharLinkedList.java new file mode 100644 index 0000000..3980c01 --- /dev/null +++ b/src/gnu/trove/list/linked/TCharLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TCharFunction; +import gnu.trove.list.TCharList; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.TCharCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of char primitives. + */ +public class TCharLinkedList implements TCharList, Externalizable { + private char no_entry_value; + private int size; + + private TCharLink head = null; + private TCharLink tail = head; + + public TCharLinkedList() { + this(Constants.DEFAULT_CHAR_NO_ENTRY_VALUE); + } + + public TCharLinkedList(char no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TCharLinkedList(TCharList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TCharIterator iterator = list.iterator(); iterator.hasNext();) { + char next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(char val) { + TCharLink l = new TCharLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals) { + for (char val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + char val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char value) { + TCharLinkedList tmp = new TCharLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TCharLinkedList tmp) { + TCharLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TCharLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TCharLinkedList link(char[] values, int valOffset, int len) { + TCharLinkedList ret = new TCharLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TCharLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TCharLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TCharLink getLink(TCharLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TCharLink getLink(TCharLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public char set(int offset, char val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TCharLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + char prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + char value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public char replace(int offset, char val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char value) { + boolean changed = false; + for (TCharLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TCharLink from the list + * + * @param l + */ + private void removeLink(TCharLink l) { + if (no(l)) + return; + + size--; + + TCharLink prev = l.getPrevious(); + TCharLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Character) { + Character i = (Character) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + if (isEmpty()) + return false; + + for (TCharIterator it = collection.iterator(); it.hasNext();) { + char i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + if (isEmpty()) + return false; + + for (char i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Character v : collection) { + if (add(v.charValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + boolean ret = false; + for (TCharIterator it = collection.iterator(); it.hasNext();) { + char i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + boolean ret = false; + for (char i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + Arrays.sort(array); + + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + Arrays.sort(array); + + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public char removeAt(int offset) { + TCharLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + char prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + for (TCharLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TCharLink h = head; + TCharLink t = tail; + TCharLink prev, next, tmp; + + // + TCharLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TCharLink start = getLinkAt(from); + TCharLink stop = getLinkAt(to); + TCharLink prev, next; + TCharLink tmp = null; + + TCharLink tmpHead = start.getPrevious(); + + // + TCharLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TCharLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TCharList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TCharLinkedList ret = new TCharLinkedList(); + TCharLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return toArray(new char[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(int offset, int len) { + return toArray(new char[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TCharLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + for (TCharLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TCharProcedure procedure) { + for (TCharLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TCharList tmp = subList(fromIndex, toIndex); + char[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(char val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, char val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TCharLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TCharLink middle; + int mid; + int from = fromIndex; + TCharLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(char value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, char value) { + int count = offset; + + TCharLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(char value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, char value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TCharLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char value) { + if (isEmpty()) + return false; + + for (TCharLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharIterator() { + TCharLink l = head; + TCharLink current; + + @Override + public char next() { + if (no(l)) + throw new NoSuchElementException(); + + char ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TCharList grep(TCharProcedure condition) { + TCharList ret = new TCharLinkedList(); + for (TCharLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TCharList inverseGrep(TCharProcedure condition) { + TCharList ret = new TCharLinkedList(); + for (TCharLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public char max() { + char ret = Character.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TCharLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char min() { + char ret = Character.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TCharLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char sum() { + char sum = 0; + + for (TCharLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TCharLink { + char value; + TCharLink previous; + TCharLink next; + + TCharLink(char value) { + this.value = value; + } + + public char getValue() { + return value; + } + + public void setValue(char value) { + this.value = value; + } + + public TCharLink getPrevious() { + return previous; + } + + public void setPrevious(TCharLink previous) { + this.previous = previous; + } + + public TCharLink getNext() { + return next; + } + + public void setNext(TCharLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TCharProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(char value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TCharIterator iterator = iterator(); iterator.hasNext();) { + char next = iterator.next(); + out.writeChar(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readChar()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TCharList)) + return false; + + TCharList that = (TCharList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TCharIterator it = iterator(); + while (it.hasNext()) { + char next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TCharLinkedList diff --git a/src/gnu/trove/list/linked/TDoubleLinkedList.java b/src/gnu/trove/list/linked/TDoubleLinkedList.java new file mode 100644 index 0000000..f8a4be8 --- /dev/null +++ b/src/gnu/trove/list/linked/TDoubleLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TDoubleFunction; +import gnu.trove.list.TDoubleList; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.TDoubleCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of double primitives. + */ +public class TDoubleLinkedList implements TDoubleList, Externalizable { + private double no_entry_value; + private int size; + + private TDoubleLink head = null; + private TDoubleLink tail = head; + + public TDoubleLinkedList() { + this(Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE); + } + + public TDoubleLinkedList(double no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TDoubleLinkedList(TDoubleList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TDoubleIterator iterator = list.iterator(); iterator.hasNext();) { + double next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(double val) { + TDoubleLink l = new TDoubleLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals) { + for (double val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + double val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double value) { + TDoubleLinkedList tmp = new TDoubleLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TDoubleLinkedList tmp) { + TDoubleLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TDoubleLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TDoubleLinkedList link(double[] values, int valOffset, int len) { + TDoubleLinkedList ret = new TDoubleLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TDoubleLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TDoubleLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TDoubleLink getLink(TDoubleLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TDoubleLink getLink(TDoubleLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public double set(int offset, double val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TDoubleLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + double prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + double value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public double replace(int offset, double val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double value) { + boolean changed = false; + for (TDoubleLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TDoubleLink from the list + * + * @param l + */ + private void removeLink(TDoubleLink l) { + if (no(l)) + return; + + size--; + + TDoubleLink prev = l.getPrevious(); + TDoubleLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Double) { + Double i = (Double) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + if (isEmpty()) + return false; + + for (TDoubleIterator it = collection.iterator(); it.hasNext();) { + double i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + if (isEmpty()) + return false; + + for (double i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Double v : collection) { + if (add(v.doubleValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + boolean ret = false; + for (TDoubleIterator it = collection.iterator(); it.hasNext();) { + double i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + boolean ret = false; + for (double i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + Arrays.sort(array); + + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + Arrays.sort(array); + + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public double removeAt(int offset) { + TDoubleLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + double prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + for (TDoubleLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TDoubleLink h = head; + TDoubleLink t = tail; + TDoubleLink prev, next, tmp; + + // + TDoubleLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TDoubleLink start = getLinkAt(from); + TDoubleLink stop = getLinkAt(to); + TDoubleLink prev, next; + TDoubleLink tmp = null; + + TDoubleLink tmpHead = start.getPrevious(); + + // + TDoubleLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TDoubleLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TDoubleList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TDoubleLinkedList ret = new TDoubleLinkedList(); + TDoubleLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return toArray(new double[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(int offset, int len) { + return toArray(new double[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TDoubleLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + for (TDoubleLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TDoubleList tmp = subList(fromIndex, toIndex); + double[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(double val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, double val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TDoubleLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TDoubleLink middle; + int mid; + int from = fromIndex; + TDoubleLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(double value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, double value) { + int count = offset; + + TDoubleLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(double value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, double value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TDoubleLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double value) { + if (isEmpty()) + return false; + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleIterator() { + TDoubleLink l = head; + TDoubleLink current; + + @Override + public double next() { + if (no(l)) + throw new NoSuchElementException(); + + double ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList grep(TDoubleProcedure condition) { + TDoubleList ret = new TDoubleLinkedList(); + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + TDoubleList ret = new TDoubleLinkedList(); + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public double max() { + double ret = Double.NEGATIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double min() { + double ret = Double.POSITIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double sum() { + double sum = 0; + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TDoubleLink { + double value; + TDoubleLink previous; + TDoubleLink next; + + TDoubleLink(double value) { + this.value = value; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } + + public TDoubleLink getPrevious() { + return previous; + } + + public void setPrevious(TDoubleLink previous) { + this.previous = previous; + } + + public TDoubleLink getNext() { + return next; + } + + public void setNext(TDoubleLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TDoubleProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(double value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TDoubleIterator iterator = iterator(); iterator.hasNext();) { + double next = iterator.next(); + out.writeDouble(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readDouble()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TDoubleList)) + return false; + + TDoubleList that = (TDoubleList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TDoubleIterator it = iterator(); + while (it.hasNext()) { + double next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TDoubleLinkedList diff --git a/src/gnu/trove/list/linked/TFloatLinkedList.java b/src/gnu/trove/list/linked/TFloatLinkedList.java new file mode 100644 index 0000000..13a3bbb --- /dev/null +++ b/src/gnu/trove/list/linked/TFloatLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TFloatFunction; +import gnu.trove.list.TFloatList; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.TFloatCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of float primitives. + */ +public class TFloatLinkedList implements TFloatList, Externalizable { + private float no_entry_value; + private int size; + + private TFloatLink head = null; + private TFloatLink tail = head; + + public TFloatLinkedList() { + this(Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE); + } + + public TFloatLinkedList(float no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TFloatLinkedList(TFloatList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TFloatIterator iterator = list.iterator(); iterator.hasNext();) { + float next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(float val) { + TFloatLink l = new TFloatLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals) { + for (float val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + float val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float value) { + TFloatLinkedList tmp = new TFloatLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TFloatLinkedList tmp) { + TFloatLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TFloatLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TFloatLinkedList link(float[] values, int valOffset, int len) { + TFloatLinkedList ret = new TFloatLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TFloatLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TFloatLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TFloatLink getLink(TFloatLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TFloatLink getLink(TFloatLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public float set(int offset, float val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TFloatLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + float prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + float value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public float replace(int offset, float val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float value) { + boolean changed = false; + for (TFloatLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TFloatLink from the list + * + * @param l + */ + private void removeLink(TFloatLink l) { + if (no(l)) + return; + + size--; + + TFloatLink prev = l.getPrevious(); + TFloatLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Float) { + Float i = (Float) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + if (isEmpty()) + return false; + + for (TFloatIterator it = collection.iterator(); it.hasNext();) { + float i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + if (isEmpty()) + return false; + + for (float i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Float v : collection) { + if (add(v.floatValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + boolean ret = false; + for (TFloatIterator it = collection.iterator(); it.hasNext();) { + float i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + boolean ret = false; + for (float i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + Arrays.sort(array); + + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + Arrays.sort(array); + + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public float removeAt(int offset) { + TFloatLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + float prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + for (TFloatLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TFloatLink h = head; + TFloatLink t = tail; + TFloatLink prev, next, tmp; + + // + TFloatLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TFloatLink start = getLinkAt(from); + TFloatLink stop = getLinkAt(to); + TFloatLink prev, next; + TFloatLink tmp = null; + + TFloatLink tmpHead = start.getPrevious(); + + // + TFloatLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TFloatLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TFloatList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TFloatLinkedList ret = new TFloatLinkedList(); + TFloatLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return toArray(new float[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(int offset, int len) { + return toArray(new float[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TFloatLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + for (TFloatLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TFloatList tmp = subList(fromIndex, toIndex); + float[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(float val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, float val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TFloatLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TFloatLink middle; + int mid; + int from = fromIndex; + TFloatLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(float value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, float value) { + int count = offset; + + TFloatLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(float value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, float value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TFloatLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float value) { + if (isEmpty()) + return false; + + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatIterator() { + TFloatLink l = head; + TFloatLink current; + + @Override + public float next() { + if (no(l)) + throw new NoSuchElementException(); + + float ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TFloatList grep(TFloatProcedure condition) { + TFloatList ret = new TFloatLinkedList(); + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + TFloatList ret = new TFloatLinkedList(); + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public float max() { + float ret = Float.NEGATIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float min() { + float ret = Float.POSITIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float sum() { + float sum = 0; + + for (TFloatLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TFloatLink { + float value; + TFloatLink previous; + TFloatLink next; + + TFloatLink(float value) { + this.value = value; + } + + public float getValue() { + return value; + } + + public void setValue(float value) { + this.value = value; + } + + public TFloatLink getPrevious() { + return previous; + } + + public void setPrevious(TFloatLink previous) { + this.previous = previous; + } + + public TFloatLink getNext() { + return next; + } + + public void setNext(TFloatLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TFloatProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(float value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TFloatIterator iterator = iterator(); iterator.hasNext();) { + float next = iterator.next(); + out.writeFloat(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readFloat()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TFloatList)) + return false; + + TFloatList that = (TFloatList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TFloatIterator it = iterator(); + while (it.hasNext()) { + float next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TFloatLinkedList diff --git a/src/gnu/trove/list/linked/TIntLinkedList.java b/src/gnu/trove/list/linked/TIntLinkedList.java new file mode 100644 index 0000000..938a29e --- /dev/null +++ b/src/gnu/trove/list/linked/TIntLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TIntFunction; +import gnu.trove.list.TIntList; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.TIntCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of int primitives. + */ +public class TIntLinkedList implements TIntList, Externalizable { + private int no_entry_value; + private int size; + + private TIntLink head = null; + private TIntLink tail = head; + + public TIntLinkedList() { + this(Constants.DEFAULT_INT_NO_ENTRY_VALUE); + } + + public TIntLinkedList(int no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TIntLinkedList(TIntList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TIntIterator iterator = list.iterator(); iterator.hasNext();) { + int next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(int val) { + TIntLink l = new TIntLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals) { + for (int val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + int val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int value) { + TIntLinkedList tmp = new TIntLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TIntLinkedList tmp) { + TIntLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TIntLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TIntLinkedList link(int[] values, int valOffset, int len) { + TIntLinkedList ret = new TIntLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TIntLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TIntLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TIntLink getLink(TIntLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TIntLink getLink(TIntLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public int set(int offset, int val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TIntLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + int prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + int value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public int replace(int offset, int val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int value) { + boolean changed = false; + for (TIntLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TIntLink from the list + * + * @param l + */ + private void removeLink(TIntLink l) { + if (no(l)) + return; + + size--; + + TIntLink prev = l.getPrevious(); + TIntLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Integer) { + Integer i = (Integer) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + if (isEmpty()) + return false; + + for (TIntIterator it = collection.iterator(); it.hasNext();) { + int i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + if (isEmpty()) + return false; + + for (int i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Integer v : collection) { + if (add(v.intValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + boolean ret = false; + for (TIntIterator it = collection.iterator(); it.hasNext();) { + int i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + boolean ret = false; + for (int i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + Arrays.sort(array); + + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + Arrays.sort(array); + + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public int removeAt(int offset) { + TIntLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + int prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + for (TIntLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TIntLink h = head; + TIntLink t = tail; + TIntLink prev, next, tmp; + + // + TIntLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TIntLink start = getLinkAt(from); + TIntLink stop = getLinkAt(to); + TIntLink prev, next; + TIntLink tmp = null; + + TIntLink tmpHead = start.getPrevious(); + + // + TIntLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TIntLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TIntList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TIntLinkedList ret = new TIntLinkedList(); + TIntLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return toArray(new int[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int offset, int len) { + return toArray(new int[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TIntLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + for (TIntLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TIntProcedure procedure) { + for (TIntLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TIntList tmp = subList(fromIndex, toIndex); + int[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(int val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, int val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TIntLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TIntLink middle; + int mid; + int from = fromIndex; + TIntLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, int value) { + int count = offset; + + TIntLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, int value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TIntLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int value) { + if (isEmpty()) + return false; + + for (TIntLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntIterator() { + TIntLink l = head; + TIntLink current; + + @Override + public int next() { + if (no(l)) + throw new NoSuchElementException(); + + int ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TIntList grep(TIntProcedure condition) { + TIntList ret = new TIntLinkedList(); + for (TIntLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TIntList inverseGrep(TIntProcedure condition) { + TIntList ret = new TIntLinkedList(); + for (TIntLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public int max() { + int ret = Integer.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TIntLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int min() { + int ret = Integer.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TIntLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int sum() { + int sum = 0; + + for (TIntLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TIntLink { + int value; + TIntLink previous; + TIntLink next; + + TIntLink(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public TIntLink getPrevious() { + return previous; + } + + public void setPrevious(TIntLink previous) { + this.previous = previous; + } + + public TIntLink getNext() { + return next; + } + + public void setNext(TIntLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TIntProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(int value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TIntIterator iterator = iterator(); iterator.hasNext();) { + int next = iterator.next(); + out.writeInt(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readInt()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TIntList)) + return false; + + TIntList that = (TIntList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TIntIterator it = iterator(); + while (it.hasNext()) { + int next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TIntLinkedList diff --git a/src/gnu/trove/list/linked/TLinkedList.java b/src/gnu/trove/list/linked/TLinkedList.java new file mode 100644 index 0000000..88c2ffa --- /dev/null +++ b/src/gnu/trove/list/linked/TLinkedList.java @@ -0,0 +1,849 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.list.TLinkable; +import gnu.trove.procedure.TObjectProcedure; + +import java.io.*; +import java.util.AbstractSequentialList; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.lang.reflect.Array; + +/** + *

+ * A LinkedList implementation which holds instances of type TLinkable. + *

+ * Using this implementation allows you to get java.util.LinkedList behavior (a + * doubly linked list, with Iterators that support insert and delete operations) + * without incurring the overhead of creating Node wrapper objects for + * every element in your list. + *

+ * The requirement to achieve this time/space gain is that the Objects stored in + * the ListCommand implement the TLinkable interface. + *

+ * The limitations are: + *

    + *
  • the same object cannot be put into more than one list at the same time. + *
  • the same object cannot be put into the same list more than once at the + * same time. + *
  • objects must only be removed from list they are in. That is, if you have + * an object A and lists l1 and l2, you must ensure that you invoke + * ListCommand.remove(A) on the correct list. + *
  • It is also forbidden to invoke ListCommand.remove() with an unaffiliated + * TLinkable (one that belongs to no list): this will destroy the list you + * invoke it on. + *
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: TLinkedList.java,v 1.1.2.3 2010/09/27 17:23:07 robeden Exp $ + * @see gnu.trove.list.TLinkable + */ + +public class TLinkedList> extends AbstractSequentialList implements Externalizable { + + static final long serialVersionUID = 1L; + + /** the head of the list */ + protected T _head; + /** the tail of the list */ + protected T _tail; + /** the number of elements in the list */ + protected int _size = 0; + + /** Creates a new TLinkedList instance. */ + public TLinkedList() { + super(); + } + + /** + * Returns an iterator positioned at index. Assuming that the list has + * a value at that index, calling next() will retrieve and advance the iterator. + * Assuming that there is a value before index in the list, calling + * previous() will retrieve it (the value at index - 1) and move the iterator to + * that position. So, iterating from front to back starts at 0; iterating from + * back to front starts at size(). + * + * @param index + * an int value + * @return a ListIterator value + */ + @Override + public ListIterator listIterator(int index) { + return new IteratorImpl(index); + } + + /** + * Returns the number of elements in the list. + * + * @return an int value + */ + @Override + public int size() { + return _size; + } + + /** + * Inserts linkable at index index in the list. All values > + * index are shifted over one position to accommodate the new addition. + * + * @param index + * an int value + * @param linkable + * an object of type TLinkable + */ + @Override + public void add(int index, T linkable) { + if (index < 0 || index > size()) { + throw new IndexOutOfBoundsException("index:" + index); + } + insert(index, linkable); + } + + /** + * Appends linkable to the end of the list. + * + * @param linkable + * an object of type TLinkable + * @return always true + */ + @Override + public boolean add(T linkable) { + insert(_size, linkable); + return true; + } + + /** + * Inserts linkable at the head of the list. + * + * @param linkable + * an object of type TLinkable + */ + public void addFirst(T linkable) { + insert(0, linkable); + } + + /** + * Adds linkable to the end of the list. + * + * @param linkable + * an object of type TLinkable + */ + public void addLast(T linkable) { + insert(size(), linkable); + } + + /** Empties the list. */ + @Override + public void clear() { + if (null != _head) { + for (TLinkable link = _head.getNext(); link != null; link = link.getNext()) { + TLinkable prev = link.getPrevious(); + prev.setNext(null); + link.setPrevious(null); + } + _head = _tail = null; + } + _size = 0; + } + + /** + * Copies the list's contents into a native array. This will be a shallow copy: + * the Tlinkable instances in the Object[] array have links to one another: + * changing those will put this list into an unpredictable state. Holding a + * reference to one element in the list will prevent the others from being + * garbage collected unless you clear the next/previous links. Caveat + * programmer! + * + * @return an Object[] value + */ + @Override + public Object[] toArray() { + Object[] o = new Object[_size]; + int i = 0; + for (TLinkable link = _head; link != null; link = link.getNext()) { + o[i++] = link; + } + return o; + } + + /** + * Copies the list to a native array, destroying the next/previous links as the + * copy is made. This list will be emptied after the copy (as if clear() had + * been invoked). The Object[] array returned will contain TLinkables that do + * not hold references to one another and so are less likely to be the + * cause of memory leaks. + * + * @return an Object[] value + */ + public Object[] toUnlinkedArray() { + Object[] o = new Object[_size]; + int i = 0; + for (TLinkable link = _head, tmp; link != null; i++) { + o[i] = link; + tmp = link; + link = link.getNext(); + tmp.setNext(null); // clear the links + tmp.setPrevious(null); + } + _size = 0; // clear the list + _head = _tail = null; + return o; + } + + /** + * Returns a typed array of the objects in the set. + * + * @param a + * an Object[] value + * @return an Object[] value + */ + @SuppressWarnings({ "unchecked" }) + public T[] toUnlinkedArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); + } + + int i = 0; + for (T link = _head, tmp; link != null; i++) { + a[i] = link; + tmp = link; + link = link.getNext(); + tmp.setNext(null); // clear the links + tmp.setPrevious(null); + } + _size = 0; // clear the list + _head = _tail = null; + return a; + } + + /** + * A linear search for o in the list. + * + * @param o + * an Object value + * @return a boolean value + */ + @Override + public boolean contains(Object o) { + for (TLinkable link = _head; link != null; link = link.getNext()) { + if (o.equals(link)) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public T get(int index) { + // Blow out for bogus values + if (index < 0 || index >= _size) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + _size); + } + + // Determine if it's better to get there from the front or the back + if (index > (_size >> 1)) { + int position = _size - 1; + T node = _tail; + + while (position > index) { + node = node.getPrevious(); + position--; + } + + return node; + } else { + int position = 0; + T node = _head; + + while (position < index) { + node = node.getNext(); + position++; + } + + return node; + } + } + + /** + * Returns the head of the list + * + * @return an Object value + */ + public T getFirst() { + return _head; + } + + /** + * Returns the tail of the list. + * + * @return an Object value + */ + public T getLast() { + return _tail; + } + + /** + * Return the node following the given node. This method exists for two reasons: + *
    + *
  1. It's really not recommended that the methods implemented by TLinkable be + * called directly since they're used internally by this class.
  2. + *
  3. This solves problems arising from generics when working with the linked + * objects directly.
  4. + *
+ *

+ * NOTE: this should only be used with nodes contained in the list. The results + * are undefined with anything else. + * + * @param current + * The current node + * @return the node after the current node + */ + @SuppressWarnings({ "unchecked" }) + public T getNext(T current) { + return current.getNext(); + } + + /** + * Return the node preceding the given node. This method exists for two reasons: + *

    + *
  1. It's really not recommended that the methods implemented by TLinkable be + * called directly since they're used internally by this class.
  2. + *
  3. This solves problems arising from generics when working with the linked + * objects directly.
  4. + *
+ *

+ * NOTE: this should only be used with nodes contained in the list. The results + * are undefined with anything else. + * + * @param current + * The current node + * @return the node after the current node + */ + @SuppressWarnings({ "unchecked" }) + public T getPrevious(T current) { + return current.getPrevious(); + } + + /** + * Remove and return the first element in the list. + * + * @return an Object value + */ + @SuppressWarnings({ "unchecked" }) + public T removeFirst() { + T o = _head; + + if (o == null) { + return null; + } + + T n = o.getNext(); + o.setNext(null); + + if (null != n) { + n.setPrevious(null); + } + + _head = n; + if (--_size == 0) { + _tail = null; + } + return o; + } + + /** + * Remove and return the last element in the list. + * + * @return an Object value + */ + @SuppressWarnings({ "unchecked" }) + public T removeLast() { + T o = _tail; + + if (o == null) { + return null; + } + + T prev = o.getPrevious(); + o.setPrevious(null); + + if (null != prev) { + prev.setNext(null); + } + _tail = prev; + if (--_size == 0) { + _head = null; + } + return o; + } + + /** + * Implementation of index-based list insertions. + * + * @param index + * an int value + * @param linkable + * an object of type TLinkable + */ + @SuppressWarnings({ "unchecked" }) + protected void insert(int index, T linkable) { + + if (_size == 0) { + _head = _tail = linkable; // first insertion + } else if (index == 0) { + linkable.setNext(_head); // insert at front + _head.setPrevious(linkable); + _head = linkable; + } else if (index == _size) { // insert at back + _tail.setNext(linkable); + linkable.setPrevious(_tail); + _tail = linkable; + } else { + T node = get(index); + + T before = node.getPrevious(); + if (before != null) { + before.setNext(linkable); + } + + linkable.setPrevious(before); + linkable.setNext(node); + node.setPrevious(linkable); + } + _size++; + } + + /** + * Removes the specified element from the list. Note that it is the caller's + * responsibility to ensure that the element does, in fact, belong to this list + * and not another instance of TLinkedList. + * + * @param o + * a TLinkable element already inserted in this list. + * @return true if the element was a TLinkable and removed + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + if (o instanceof TLinkable) { + T p, n; + TLinkable link = (TLinkable) o; + + p = link.getPrevious(); + n = link.getNext(); + + if (n == null && p == null) { // emptying the list + // It's possible this object is not something that's in the list. So, + // make sure it's the head if it doesn't point to anything. This solves + // problems caused by removing something multiple times. + if (o != _head) { + return false; + } + + _head = _tail = null; + } else if (n == null) { // this is the tail + // make previous the new tail + link.setPrevious(null); + p.setNext(null); + _tail = p; + } else if (p == null) { // this is the head + // make next the new head + link.setNext(null); + n.setPrevious(null); + _head = n; + } else { // somewhere in the middle + p.setNext(n); + n.setPrevious(p); + link.setNext(null); + link.setPrevious(null); + } + + _size--; // reduce size of list + return true; + } else { + return false; + } + } + + /** + * Inserts newElement into the list immediately before current. All elements to + * the right of and including current are shifted over. + * + * @param current + * a TLinkable value currently in the list. + * @param newElement + * a TLinkable value to be added to the list. + */ + public void addBefore(T current, T newElement) { + if (current == _head) { + addFirst(newElement); + } else if (current == null) { + addLast(newElement); + } else { + T p = current.getPrevious(); + newElement.setNext(current); + p.setNext(newElement); + newElement.setPrevious(p); + current.setPrevious(newElement); + _size++; + } + } + + /** + * Inserts newElement into the list immediately after current. All elements to + * the left of and including current are shifted over. + * + * @param current + * a TLinkable value currently in the list. + * @param newElement + * a TLinkable value to be added to the list. + */ + public void addAfter(T current, T newElement) { + if (current == _tail) { + addLast(newElement); + } else if (current == null) { + addFirst(newElement); + } else { + T n = current.getNext(); + newElement.setPrevious(current); + newElement.setNext(n); + current.setNext(newElement); + n.setPrevious(newElement); + _size++; + } + } + + /** + * Executes procedure for each entry in the list. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @SuppressWarnings({ "unchecked" }) + public boolean forEachValue(TObjectProcedure procedure) { + T node = _head; + while (node != null) { + boolean keep_going = procedure.execute(node); + if (!keep_going) { + return false; + } + + node = node.getNext(); + } + + return true; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // HEAD + out.writeObject(_head); + + // TAIL + out.writeObject(_tail); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NUMBER OF ENTRIED + _size = in.readInt(); + + // HEAD + _head = (T) in.readObject(); + + // TAIL + _tail = (T) in.readObject(); + } + + /** A ListIterator that supports additions and deletions. */ + protected final class IteratorImpl implements ListIterator { + + private int _nextIndex = 0; + private T _next; + private T _lastReturned; + + /** + * Creates a new Iterator instance positioned at index. + * + * @param position + * an int value + */ + @SuppressWarnings({ "unchecked" }) + IteratorImpl(int position) { + if (position < 0 || position > _size) { + throw new IndexOutOfBoundsException(); + } + + _nextIndex = position; + if (position == 0) { + _next = _head; + } else if (position == _size) { + _next = null; + } else if (position < (_size >> 1)) { + int pos = 0; + for (_next = _head; pos < position; pos++) { + _next = _next.getNext(); + } + } else { + int pos = _size - 1; + for (_next = _tail; pos > position; pos--) { + _next = _next.getPrevious(); + } + } + } + + /** + * Insert linkable at the current position of the iterator. Calling + * next() after add() will return the added object. + * + * @param linkable + * an object of type TLinkable + */ + @Override + public final void add(T linkable) { + _lastReturned = null; + _nextIndex++; + + if (_size == 0) { + TLinkedList.this.add(linkable); + } else { + TLinkedList.this.addBefore(_next, linkable); + } + } + + /** + * True if a call to next() will return an object. + * + * @return a boolean value + */ + @Override + public final boolean hasNext() { + return _nextIndex != _size; + } + + /** + * True if a call to previous() will return a value. + * + * @return a boolean value + */ + @Override + public final boolean hasPrevious() { + return _nextIndex != 0; + } + + /** + * Returns the value at the Iterator's index and advances the iterator. + * + * @return an Object value + * @throws NoSuchElementException + * if there is no next element + */ + @Override + @SuppressWarnings({ "unchecked" }) + public final T next() { + if (_nextIndex == _size) { + throw new NoSuchElementException(); + } + + _lastReturned = _next; + _next = _next.getNext(); + _nextIndex++; + return _lastReturned; + } + + /** + * returns the index of the next node in the list (the one that would be + * returned by a call to next()). + * + * @return an int value + */ + @Override + public final int nextIndex() { + return _nextIndex; + } + + /** + * Returns the value before the Iterator's index and moves the iterator back one + * index. + * + * @return an Object value + * @throws NoSuchElementException + * if there is no previous element. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public final T previous() { + if (_nextIndex == 0) { + throw new NoSuchElementException(); + } + + if (_nextIndex == _size) { + _lastReturned = _next = _tail; + } else { + _lastReturned = _next = _next.getPrevious(); + } + + _nextIndex--; + return _lastReturned; + } + + /** + * Returns the previous element's index. + * + * @return an int value + */ + @Override + public final int previousIndex() { + return _nextIndex - 1; + } + + /** + * Removes the current element in the list and shrinks its size accordingly. + * + * @throws IllegalStateException + * neither next nor previous have been invoked, or remove or add + * have been invoked after the last invocation of next or previous. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public final void remove() { + if (_lastReturned == null) { + throw new IllegalStateException("must invoke next or previous before invoking remove"); + } + + if (_lastReturned != _next) { + _nextIndex--; + } + _next = _lastReturned.getNext(); + TLinkedList.this.remove(_lastReturned); + _lastReturned = null; + } + + /** + * Replaces the current element in the list with linkable + * + * @param linkable + * an object of type TLinkable + */ + @Override + public final void set(T linkable) { + if (_lastReturned == null) { + throw new IllegalStateException(); + } + + swap(_lastReturned, linkable); + _lastReturned = linkable; + } + + /** + * Replace from with to in the list. + * + * @param from + * a TLinkable value + * @param to + * a TLinkable value + */ + private void swap(T from, T to) { + T from_p = from.getPrevious(); + T from_n = from.getNext(); + + T to_p = to.getPrevious(); + T to_n = to.getNext(); + + // NOTE: 'to' cannot be null at this point + if (from_n == to) { + if (from_p != null) + from_p.setNext(to); + to.setPrevious(from_p); + to.setNext(from); + from.setPrevious(to); + from.setNext(to_n); + if (to_n != null) + to_n.setPrevious(from); + } + // NOTE: 'from' cannot be null at this point + else if (to_n == from) { + if (to_p != null) + to_p.setNext(to); + to.setPrevious(from); + to.setNext(from_n); + from.setPrevious(to_p); + from.setNext(to); + if (from_n != null) + from_n.setPrevious(to); + } else { + from.setNext(to_n); + from.setPrevious(to_p); + if (to_p != null) + to_p.setNext(from); + if (to_n != null) + to_n.setPrevious(from); + + to.setNext(from_n); + to.setPrevious(from_p); + if (from_p != null) + from_p.setNext(to); + if (from_n != null) + from_n.setPrevious(to); + } + + if (_head == from) + _head = to; + else if (_head == to) + _head = from; + + if (_tail == from) + _tail = to; + else if (_tail == to) + _tail = from; + + if (_lastReturned == from) + _lastReturned = to; + else if (_lastReturned == to) + _lastReturned = from; + + if (_next == from) + _next = to; + else if (_next == to) + _next = from; + } + } +} // TLinkedList diff --git a/src/gnu/trove/list/linked/TLongLinkedList.java b/src/gnu/trove/list/linked/TLongLinkedList.java new file mode 100644 index 0000000..fe3a611 --- /dev/null +++ b/src/gnu/trove/list/linked/TLongLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TLongFunction; +import gnu.trove.list.TLongList; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.TLongCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of long primitives. + */ +public class TLongLinkedList implements TLongList, Externalizable { + private long no_entry_value; + private int size; + + private TLongLink head = null; + private TLongLink tail = head; + + public TLongLinkedList() { + this(Constants.DEFAULT_LONG_NO_ENTRY_VALUE); + } + + public TLongLinkedList(long no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TLongLinkedList(TLongList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TLongIterator iterator = list.iterator(); iterator.hasNext();) { + long next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(long val) { + TLongLink l = new TLongLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals) { + for (long val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + long val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long value) { + TLongLinkedList tmp = new TLongLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TLongLinkedList tmp) { + TLongLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TLongLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TLongLinkedList link(long[] values, int valOffset, int len) { + TLongLinkedList ret = new TLongLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TLongLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TLongLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TLongLink getLink(TLongLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TLongLink getLink(TLongLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public long set(int offset, long val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TLongLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + long prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + long value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public long replace(int offset, long val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long value) { + boolean changed = false; + for (TLongLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TLongLink from the list + * + * @param l + */ + private void removeLink(TLongLink l) { + if (no(l)) + return; + + size--; + + TLongLink prev = l.getPrevious(); + TLongLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Long) { + Long i = (Long) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + if (isEmpty()) + return false; + + for (TLongIterator it = collection.iterator(); it.hasNext();) { + long i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + if (isEmpty()) + return false; + + for (long i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Long v : collection) { + if (add(v.longValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + boolean ret = false; + for (TLongIterator it = collection.iterator(); it.hasNext();) { + long i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + boolean ret = false; + for (long i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + Arrays.sort(array); + + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + Arrays.sort(array); + + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public long removeAt(int offset) { + TLongLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + long prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + for (TLongLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TLongLink h = head; + TLongLink t = tail; + TLongLink prev, next, tmp; + + // + TLongLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TLongLink start = getLinkAt(from); + TLongLink stop = getLinkAt(to); + TLongLink prev, next; + TLongLink tmp = null; + + TLongLink tmpHead = start.getPrevious(); + + // + TLongLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TLongLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TLongList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TLongLinkedList ret = new TLongLinkedList(); + TLongLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return toArray(new long[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(int offset, int len) { + return toArray(new long[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TLongLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + for (TLongLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TLongProcedure procedure) { + for (TLongLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TLongList tmp = subList(fromIndex, toIndex); + long[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(long val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, long val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TLongLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TLongLink middle; + int mid; + int from = fromIndex; + TLongLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(long value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, long value) { + int count = offset; + + TLongLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(long value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, long value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TLongLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long value) { + if (isEmpty()) + return false; + + for (TLongLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongIterator() { + TLongLink l = head; + TLongLink current; + + @Override + public long next() { + if (no(l)) + throw new NoSuchElementException(); + + long ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TLongList grep(TLongProcedure condition) { + TLongList ret = new TLongLinkedList(); + for (TLongLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TLongList inverseGrep(TLongProcedure condition) { + TLongList ret = new TLongLinkedList(); + for (TLongLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public long max() { + long ret = Long.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TLongLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long min() { + long ret = Long.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TLongLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long sum() { + long sum = 0; + + for (TLongLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TLongLink { + long value; + TLongLink previous; + TLongLink next; + + TLongLink(long value) { + this.value = value; + } + + public long getValue() { + return value; + } + + public void setValue(long value) { + this.value = value; + } + + public TLongLink getPrevious() { + return previous; + } + + public void setPrevious(TLongLink previous) { + this.previous = previous; + } + + public TLongLink getNext() { + return next; + } + + public void setNext(TLongLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TLongProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(long value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TLongIterator iterator = iterator(); iterator.hasNext();) { + long next = iterator.next(); + out.writeLong(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readLong()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TLongList)) + return false; + + TLongList that = (TLongList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TLongIterator it = iterator(); + while (it.hasNext()) { + long next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TLongLinkedList diff --git a/src/gnu/trove/list/linked/TShortLinkedList.java b/src/gnu/trove/list/linked/TShortLinkedList.java new file mode 100644 index 0000000..b1ee750 --- /dev/null +++ b/src/gnu/trove/list/linked/TShortLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TShortFunction; +import gnu.trove.list.TShortList; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.TShortCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of short primitives. + */ +public class TShortLinkedList implements TShortList, Externalizable { + private short no_entry_value; + private int size; + + private TShortLink head = null; + private TShortLink tail = head; + + public TShortLinkedList() { + this(Constants.DEFAULT_SHORT_NO_ENTRY_VALUE); + } + + public TShortLinkedList(short no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TShortLinkedList(TShortList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TShortIterator iterator = list.iterator(); iterator.hasNext();) { + short next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(short val) { + TShortLink l = new TShortLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals) { + for (short val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + short val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short value) { + TShortLinkedList tmp = new TShortLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TShortLinkedList tmp) { + TShortLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TShortLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TShortLinkedList link(short[] values, int valOffset, int len) { + TShortLinkedList ret = new TShortLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TShortLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TShortLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TShortLink getLink(TShortLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TShortLink getLink(TShortLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public short set(int offset, short val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TShortLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + short prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + short value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public short replace(int offset, short val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short value) { + boolean changed = false; + for (TShortLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TShortLink from the list + * + * @param l + */ + private void removeLink(TShortLink l) { + if (no(l)) + return; + + size--; + + TShortLink prev = l.getPrevious(); + TShortLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Short) { + Short i = (Short) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + if (isEmpty()) + return false; + + for (TShortIterator it = collection.iterator(); it.hasNext();) { + short i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + if (isEmpty()) + return false; + + for (short i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Short v : collection) { + if (add(v.shortValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + boolean ret = false; + for (TShortIterator it = collection.iterator(); it.hasNext();) { + short i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + boolean ret = false; + for (short i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + Arrays.sort(array); + + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + Arrays.sort(array); + + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public short removeAt(int offset) { + TShortLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + short prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + for (TShortLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TShortLink h = head; + TShortLink t = tail; + TShortLink prev, next, tmp; + + // + TShortLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TShortLink start = getLinkAt(from); + TShortLink stop = getLinkAt(to); + TShortLink prev, next; + TShortLink tmp = null; + + TShortLink tmpHead = start.getPrevious(); + + // + TShortLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TShortLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TShortList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TShortLinkedList ret = new TShortLinkedList(); + TShortLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return toArray(new short[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(int offset, int len) { + return toArray(new short[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TShortLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + for (TShortLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TShortProcedure procedure) { + for (TShortLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TShortList tmp = subList(fromIndex, toIndex); + short[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(short val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, short val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TShortLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TShortLink middle; + int mid; + int from = fromIndex; + TShortLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(short value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, short value) { + int count = offset; + + TShortLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(short value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, short value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TShortLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short value) { + if (isEmpty()) + return false; + + for (TShortLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortIterator() { + TShortLink l = head; + TShortLink current; + + @Override + public short next() { + if (no(l)) + throw new NoSuchElementException(); + + short ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TShortList grep(TShortProcedure condition) { + TShortList ret = new TShortLinkedList(); + for (TShortLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TShortList inverseGrep(TShortProcedure condition) { + TShortList ret = new TShortLinkedList(); + for (TShortLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public short max() { + short ret = Short.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TShortLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short min() { + short ret = Short.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TShortLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short sum() { + short sum = 0; + + for (TShortLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TShortLink { + short value; + TShortLink previous; + TShortLink next; + + TShortLink(short value) { + this.value = value; + } + + public short getValue() { + return value; + } + + public void setValue(short value) { + this.value = value; + } + + public TShortLink getPrevious() { + return previous; + } + + public void setPrevious(TShortLink previous) { + this.previous = previous; + } + + public TShortLink getNext() { + return next; + } + + public void setNext(TShortLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TShortProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(short value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TShortIterator iterator = iterator(); iterator.hasNext();) { + short next = iterator.next(); + out.writeShort(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readShort()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TShortList)) + return false; + + TShortList that = (TShortList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TShortIterator it = iterator(); + while (it.hasNext()) { + short next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TShortLinkedList diff --git a/src/gnu/trove/map/TByteByteMap.java b/src/gnu/trove/map/TByteByteMap.java new file mode 100644 index 0000000..cdfcc43 --- /dev/null +++ b/src/gnu/trove/map/TByteByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and byte values. + */ +public interface TByteByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(byte key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(byte key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteByteIterator with access to this map's keys and values + */ + public TByteByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TByteCharMap.java b/src/gnu/trove/map/TByteCharMap.java new file mode 100644 index 0000000..4cdce9a --- /dev/null +++ b/src/gnu/trove/map/TByteCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and char values. + */ +public interface TByteCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(byte key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(byte key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteCharIterator with access to this map's keys and values + */ + public TByteCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TByteDoubleMap.java b/src/gnu/trove/map/TByteDoubleMap.java new file mode 100644 index 0000000..230d819 --- /dev/null +++ b/src/gnu/trove/map/TByteDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and double values. + */ +public interface TByteDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(byte key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(byte key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteDoubleIterator with access to this map's keys and values + */ + public TByteDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TByteFloatMap.java b/src/gnu/trove/map/TByteFloatMap.java new file mode 100644 index 0000000..d380b02 --- /dev/null +++ b/src/gnu/trove/map/TByteFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and float values. + */ +public interface TByteFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(byte key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(byte key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteFloatIterator with access to this map's keys and values + */ + public TByteFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TByteIntMap.java b/src/gnu/trove/map/TByteIntMap.java new file mode 100644 index 0000000..c07d90c --- /dev/null +++ b/src/gnu/trove/map/TByteIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and int values. + */ +public interface TByteIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(byte key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(byte key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteIntIterator with access to this map's keys and values + */ + public TByteIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TByteLongMap.java b/src/gnu/trove/map/TByteLongMap.java new file mode 100644 index 0000000..0a3b375 --- /dev/null +++ b/src/gnu/trove/map/TByteLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and long values. + */ +public interface TByteLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(byte key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(byte key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteLongIterator with access to this map's keys and values + */ + public TByteLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TByteObjectMap.java b/src/gnu/trove/map/TByteObjectMap.java new file mode 100644 index 0000000..4078da4 --- /dev/null +++ b/src/gnu/trove/map/TByteObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TByteObjectIterator; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TByteObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TByteSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of byte keys and Object values. + */ +public interface TByteObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + byte getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(byte key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the byte value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(byte key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(byte) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(byte key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(byte key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous byte value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(byte key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(byte,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TByteObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TByteSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TByteSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + byte[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + byte[] keys(byte[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of byte values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of byte values. + */ + V[] values(V[] array); + + /** + * Returns a TByteObjectIterator with access to this map's keys and + * values. + * + * @return a TByteObjectIterator with access to this map's keys and + * values. + */ + public TByteObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TByteObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TByteShortMap.java b/src/gnu/trove/map/TByteShortMap.java new file mode 100644 index 0000000..7a14b11 --- /dev/null +++ b/src/gnu/trove/map/TByteShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and short values. + */ +public interface TByteShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(byte key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(byte key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteShortIterator with access to this map's keys and values + */ + public TByteShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TCharByteMap.java b/src/gnu/trove/map/TCharByteMap.java new file mode 100644 index 0000000..624848c --- /dev/null +++ b/src/gnu/trove/map/TCharByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and byte values. + */ +public interface TCharByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(char key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(char key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharByteIterator with access to this map's keys and values + */ + public TCharByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TCharCharMap.java b/src/gnu/trove/map/TCharCharMap.java new file mode 100644 index 0000000..4612451 --- /dev/null +++ b/src/gnu/trove/map/TCharCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and char values. + */ +public interface TCharCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(char key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(char key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharCharIterator with access to this map's keys and values + */ + public TCharCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(char key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TCharDoubleMap.java b/src/gnu/trove/map/TCharDoubleMap.java new file mode 100644 index 0000000..cac4b6c --- /dev/null +++ b/src/gnu/trove/map/TCharDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and double values. + */ +public interface TCharDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(char key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(char key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharDoubleIterator with access to this map's keys and values + */ + public TCharDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(char key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TCharFloatMap.java b/src/gnu/trove/map/TCharFloatMap.java new file mode 100644 index 0000000..f491469 --- /dev/null +++ b/src/gnu/trove/map/TCharFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and float values. + */ +public interface TCharFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(char key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(char key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharFloatIterator with access to this map's keys and values + */ + public TCharFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(char key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TCharIntMap.java b/src/gnu/trove/map/TCharIntMap.java new file mode 100644 index 0000000..2534f5c --- /dev/null +++ b/src/gnu/trove/map/TCharIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and int values. + */ +public interface TCharIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(char key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(char key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharIntIterator with access to this map's keys and values + */ + public TCharIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(char key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TCharLongMap.java b/src/gnu/trove/map/TCharLongMap.java new file mode 100644 index 0000000..4603e7d --- /dev/null +++ b/src/gnu/trove/map/TCharLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and long values. + */ +public interface TCharLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(char key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(char key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharLongIterator with access to this map's keys and values + */ + public TCharLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(char key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TCharObjectMap.java b/src/gnu/trove/map/TCharObjectMap.java new file mode 100644 index 0000000..22353a0 --- /dev/null +++ b/src/gnu/trove/map/TCharObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TCharObjectIterator; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TCharObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TCharSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of char keys and Object values. + */ +public interface TCharObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + char getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(char key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the char value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(char key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(char) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(char key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(char key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous char value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(char key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(char,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TCharObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TCharSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TCharSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + char[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + char[] keys(char[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of char values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of char values. + */ + V[] values(V[] array); + + /** + * Returns a TCharObjectIterator with access to this map's keys and + * values. + * + * @return a TCharObjectIterator with access to this map's keys and + * values. + */ + public TCharObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TCharObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TCharShortMap.java b/src/gnu/trove/map/TCharShortMap.java new file mode 100644 index 0000000..076a8cd --- /dev/null +++ b/src/gnu/trove/map/TCharShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and short values. + */ +public interface TCharShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(char key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(char key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharShortIterator with access to this map's keys and values + */ + public TCharShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(char key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TDoubleByteMap.java b/src/gnu/trove/map/TDoubleByteMap.java new file mode 100644 index 0000000..0f5340e --- /dev/null +++ b/src/gnu/trove/map/TDoubleByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and byte values. + */ +public interface TDoubleByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(double key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(double key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleByteIterator with access to this map's keys and values + */ + public TDoubleByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TDoubleCharMap.java b/src/gnu/trove/map/TDoubleCharMap.java new file mode 100644 index 0000000..7937332 --- /dev/null +++ b/src/gnu/trove/map/TDoubleCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and char values. + */ +public interface TDoubleCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(double key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(double key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleCharIterator with access to this map's keys and values + */ + public TDoubleCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(double key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TDoubleDoubleMap.java b/src/gnu/trove/map/TDoubleDoubleMap.java new file mode 100644 index 0000000..c719e0d --- /dev/null +++ b/src/gnu/trove/map/TDoubleDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and double values. + */ +public interface TDoubleDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(double key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(double key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleDoubleIterator with access to this map's keys and values + */ + public TDoubleDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(double key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TDoubleFloatMap.java b/src/gnu/trove/map/TDoubleFloatMap.java new file mode 100644 index 0000000..9526956 --- /dev/null +++ b/src/gnu/trove/map/TDoubleFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and float values. + */ +public interface TDoubleFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(double key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(double key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleFloatIterator with access to this map's keys and values + */ + public TDoubleFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(double key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TDoubleIntMap.java b/src/gnu/trove/map/TDoubleIntMap.java new file mode 100644 index 0000000..55e0a69 --- /dev/null +++ b/src/gnu/trove/map/TDoubleIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and int values. + */ +public interface TDoubleIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(double key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(double key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleIntIterator with access to this map's keys and values + */ + public TDoubleIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(double key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TDoubleLongMap.java b/src/gnu/trove/map/TDoubleLongMap.java new file mode 100644 index 0000000..9cd9cb0 --- /dev/null +++ b/src/gnu/trove/map/TDoubleLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and long values. + */ +public interface TDoubleLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(double key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(double key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleLongIterator with access to this map's keys and values + */ + public TDoubleLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(double key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TDoubleObjectMap.java b/src/gnu/trove/map/TDoubleObjectMap.java new file mode 100644 index 0000000..1b68a00 --- /dev/null +++ b/src/gnu/trove/map/TDoubleObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TDoubleObjectIterator; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TDoubleObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TDoubleSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of double keys and Object values. + */ +public interface TDoubleObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + double getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(double key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the double value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(double key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(double) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(double key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(double key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous double value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(double key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(double,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TDoubleObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TDoubleSet} view of the keys contained in this map. The set + * is backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TDoubleSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + double[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + double[] keys(double[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of double values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of double values. + */ + V[] values(V[] array); + + /** + * Returns a TDoubleObjectIterator with access to this map's keys and + * values. + * + * @return a TDoubleObjectIterator with access to this map's keys and + * values. + */ + public TDoubleObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TDoubleObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TDoubleShortMap.java b/src/gnu/trove/map/TDoubleShortMap.java new file mode 100644 index 0000000..8a390d4 --- /dev/null +++ b/src/gnu/trove/map/TDoubleShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and short values. + */ +public interface TDoubleShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(double key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(double key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleShortIterator with access to this map's keys and values + */ + public TDoubleShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(double key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TFloatByteMap.java b/src/gnu/trove/map/TFloatByteMap.java new file mode 100644 index 0000000..3b2d4d3 --- /dev/null +++ b/src/gnu/trove/map/TFloatByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and byte values. + */ +public interface TFloatByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(float key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(float key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatByteIterator with access to this map's keys and values + */ + public TFloatByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TFloatCharMap.java b/src/gnu/trove/map/TFloatCharMap.java new file mode 100644 index 0000000..7e783bf --- /dev/null +++ b/src/gnu/trove/map/TFloatCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and char values. + */ +public interface TFloatCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(float key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(float key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatCharIterator with access to this map's keys and values + */ + public TFloatCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(float key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TFloatDoubleMap.java b/src/gnu/trove/map/TFloatDoubleMap.java new file mode 100644 index 0000000..f0bc608 --- /dev/null +++ b/src/gnu/trove/map/TFloatDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and double values. + */ +public interface TFloatDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(float key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(float key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatDoubleIterator with access to this map's keys and values + */ + public TFloatDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(float key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TFloatFloatMap.java b/src/gnu/trove/map/TFloatFloatMap.java new file mode 100644 index 0000000..c3e6948 --- /dev/null +++ b/src/gnu/trove/map/TFloatFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and float values. + */ +public interface TFloatFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(float key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(float key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatFloatIterator with access to this map's keys and values + */ + public TFloatFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(float key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TFloatIntMap.java b/src/gnu/trove/map/TFloatIntMap.java new file mode 100644 index 0000000..1629996 --- /dev/null +++ b/src/gnu/trove/map/TFloatIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and int values. + */ +public interface TFloatIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(float key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(float key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatIntIterator with access to this map's keys and values + */ + public TFloatIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(float key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TFloatLongMap.java b/src/gnu/trove/map/TFloatLongMap.java new file mode 100644 index 0000000..a13acbe --- /dev/null +++ b/src/gnu/trove/map/TFloatLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and long values. + */ +public interface TFloatLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(float key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(float key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatLongIterator with access to this map's keys and values + */ + public TFloatLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(float key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TFloatObjectMap.java b/src/gnu/trove/map/TFloatObjectMap.java new file mode 100644 index 0000000..d235735 --- /dev/null +++ b/src/gnu/trove/map/TFloatObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TFloatObjectIterator; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TFloatObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TFloatSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of float keys and Object values. + */ +public interface TFloatObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + float getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(float key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the float value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(float key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(float) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(float key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(float key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous float value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(float key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(float,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TFloatObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TFloatSet} view of the keys contained in this map. The set + * is backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TFloatSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + float[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + float[] keys(float[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of float values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of float values. + */ + V[] values(V[] array); + + /** + * Returns a TFloatObjectIterator with access to this map's keys and + * values. + * + * @return a TFloatObjectIterator with access to this map's keys and + * values. + */ + public TFloatObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TFloatObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TFloatShortMap.java b/src/gnu/trove/map/TFloatShortMap.java new file mode 100644 index 0000000..b00b99d --- /dev/null +++ b/src/gnu/trove/map/TFloatShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and short values. + */ +public interface TFloatShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(float key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(float key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatShortIterator with access to this map's keys and values + */ + public TFloatShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(float key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TIntByteMap.java b/src/gnu/trove/map/TIntByteMap.java new file mode 100644 index 0000000..2bd9d36 --- /dev/null +++ b/src/gnu/trove/map/TIntByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and byte values. + */ +public interface TIntByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(int key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(int key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntByteIterator with access to this map's keys and values + */ + public TIntByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TIntCharMap.java b/src/gnu/trove/map/TIntCharMap.java new file mode 100644 index 0000000..bb3dbdc --- /dev/null +++ b/src/gnu/trove/map/TIntCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and char values. + */ +public interface TIntCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(int key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(int key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntCharIterator with access to this map's keys and values + */ + public TIntCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(int key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TIntDoubleMap.java b/src/gnu/trove/map/TIntDoubleMap.java new file mode 100644 index 0000000..59acee6 --- /dev/null +++ b/src/gnu/trove/map/TIntDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and double values. + */ +public interface TIntDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(int key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(int key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntDoubleIterator with access to this map's keys and values + */ + public TIntDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(int key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TIntFloatMap.java b/src/gnu/trove/map/TIntFloatMap.java new file mode 100644 index 0000000..1dccd8d --- /dev/null +++ b/src/gnu/trove/map/TIntFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and float values. + */ +public interface TIntFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(int key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(int key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntFloatIterator with access to this map's keys and values + */ + public TIntFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(int key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TIntIntMap.java b/src/gnu/trove/map/TIntIntMap.java new file mode 100644 index 0000000..cb0f1f9 --- /dev/null +++ b/src/gnu/trove/map/TIntIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and int values. + */ +public interface TIntIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(int key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(int key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntIntIterator with access to this map's keys and values + */ + public TIntIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(int key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TIntLongMap.java b/src/gnu/trove/map/TIntLongMap.java new file mode 100644 index 0000000..01f81d6 --- /dev/null +++ b/src/gnu/trove/map/TIntLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and long values. + */ +public interface TIntLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(int key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(int key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntLongIterator with access to this map's keys and values + */ + public TIntLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(int key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TIntObjectMap.java b/src/gnu/trove/map/TIntObjectMap.java new file mode 100644 index 0000000..e382867 --- /dev/null +++ b/src/gnu/trove/map/TIntObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TIntObjectIterator; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TIntObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TIntSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of int keys and Object values. + */ +public interface TIntObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + int getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(int key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the int value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(int key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(int) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(int key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(int key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous int value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(int key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(int,Object) put(k, v)} on this map once for each mapping from key + * k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TIntObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TIntSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TIntSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + int[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + int[] keys(int[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of int values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of int values. + */ + V[] values(V[] array); + + /** + * Returns a TIntObjectIterator with access to this map's keys and + * values. + * + * @return a TIntObjectIterator with access to this map's keys and + * values. + */ + public TIntObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TIntObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TIntShortMap.java b/src/gnu/trove/map/TIntShortMap.java new file mode 100644 index 0000000..4b7f20b --- /dev/null +++ b/src/gnu/trove/map/TIntShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and short values. + */ +public interface TIntShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(int key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(int key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntShortIterator with access to this map's keys and values + */ + public TIntShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(int key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TLongByteMap.java b/src/gnu/trove/map/TLongByteMap.java new file mode 100644 index 0000000..ac0fee2 --- /dev/null +++ b/src/gnu/trove/map/TLongByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and byte values. + */ +public interface TLongByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(long key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(long key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongByteIterator with access to this map's keys and values + */ + public TLongByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TLongCharMap.java b/src/gnu/trove/map/TLongCharMap.java new file mode 100644 index 0000000..840fbfe --- /dev/null +++ b/src/gnu/trove/map/TLongCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and char values. + */ +public interface TLongCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(long key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(long key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongCharIterator with access to this map's keys and values + */ + public TLongCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(long key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TLongDoubleMap.java b/src/gnu/trove/map/TLongDoubleMap.java new file mode 100644 index 0000000..aa7d10f --- /dev/null +++ b/src/gnu/trove/map/TLongDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and double values. + */ +public interface TLongDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(long key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(long key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongDoubleIterator with access to this map's keys and values + */ + public TLongDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(long key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TLongFloatMap.java b/src/gnu/trove/map/TLongFloatMap.java new file mode 100644 index 0000000..89726cf --- /dev/null +++ b/src/gnu/trove/map/TLongFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and float values. + */ +public interface TLongFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(long key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(long key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongFloatIterator with access to this map's keys and values + */ + public TLongFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(long key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TLongIntMap.java b/src/gnu/trove/map/TLongIntMap.java new file mode 100644 index 0000000..6fa4db5 --- /dev/null +++ b/src/gnu/trove/map/TLongIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and int values. + */ +public interface TLongIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(long key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(long key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongIntIterator with access to this map's keys and values + */ + public TLongIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(long key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TLongLongMap.java b/src/gnu/trove/map/TLongLongMap.java new file mode 100644 index 0000000..3bc107a --- /dev/null +++ b/src/gnu/trove/map/TLongLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and long values. + */ +public interface TLongLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(long key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(long key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongLongIterator with access to this map's keys and values + */ + public TLongLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(long key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TLongObjectMap.java b/src/gnu/trove/map/TLongObjectMap.java new file mode 100644 index 0000000..d2e23f5 --- /dev/null +++ b/src/gnu/trove/map/TLongObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TLongObjectIterator; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TLongObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TLongSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of long keys and Object values. + */ +public interface TLongObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + long getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(long key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the long value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(long key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(long) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(long key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(long key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous long value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(long key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(long,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TLongObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TLongSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TLongSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + long[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + long[] keys(long[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of long values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of long values. + */ + V[] values(V[] array); + + /** + * Returns a TLongObjectIterator with access to this map's keys and + * values. + * + * @return a TLongObjectIterator with access to this map's keys and + * values. + */ + public TLongObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TLongObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TLongShortMap.java b/src/gnu/trove/map/TLongShortMap.java new file mode 100644 index 0000000..e5af795 --- /dev/null +++ b/src/gnu/trove/map/TLongShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and short values. + */ +public interface TLongShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(long key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(long key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongShortIterator with access to this map's keys and values + */ + public TLongShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(long key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TMap.java b/src/gnu/trove/map/TMap.java new file mode 100644 index 0000000..10f7823 --- /dev/null +++ b/src/gnu/trove/map/TMap.java @@ -0,0 +1,95 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2011, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.function.TObjectFunction; +import gnu.trove.procedure.TObjectObjectProcedure; +import gnu.trove.procedure.TObjectProcedure; + +import java.util.Map; + +/** + * Interface extension to {@link Map} which adds Trove-specific features. + */ +public interface TMap extends Map { + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V putIfAbsent(K key, V value); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TObjectObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectObjectProcedure procedure); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TObjectObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); +} diff --git a/src/gnu/trove/map/TObjectByteMap.java b/src/gnu/trove/map/TObjectByteMap.java new file mode 100644 index 0000000..a3fafde --- /dev/null +++ b/src/gnu/trove/map/TObjectByteMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TByteCollection; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectByteProcedure; +import gnu.trove.iterator.TObjectByteIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and byte values. + */ +public interface TObjectByteMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + byte getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * byte value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(byte value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the byte value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + byte get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + byte put(K key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + byte putIfAbsent(K key, byte value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous byte value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + byte remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,byte) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectByteMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TByteCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TByteIterator.remove, + * TByteCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of byte values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of byte values. + */ + byte[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of byte values. + */ + byte[] values(byte[] array); + + /** + * Returns a TObjectByteIterator with access to this map's keys and + * values. + * + * @return a TObjectByteIterator with access to this map's keys and + * values. + */ + public TObjectByteIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(K key, byte adjust_amount, byte put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectByteProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectCharMap.java b/src/gnu/trove/map/TObjectCharMap.java new file mode 100644 index 0000000..5fe17cf --- /dev/null +++ b/src/gnu/trove/map/TObjectCharMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TCharCollection; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectCharProcedure; +import gnu.trove.iterator.TObjectCharIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and char values. + */ +public interface TObjectCharMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + char getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * char value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(char value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the char value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + char get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + char put(K key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + char putIfAbsent(K key, char value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous char value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + char remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,char) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectCharMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TCharCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TCharIterator.remove, + * TCharCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of char values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of char values. + */ + char[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of char values. + */ + char[] values(char[] array); + + /** + * Returns a TObjectCharIterator with access to this map's keys and + * values. + * + * @return a TObjectCharIterator with access to this map's keys and + * values. + */ + public TObjectCharIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(K key, char adjust_amount, char put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectCharProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectDoubleMap.java b/src/gnu/trove/map/TObjectDoubleMap.java new file mode 100644 index 0000000..fc1ce5b --- /dev/null +++ b/src/gnu/trove/map/TObjectDoubleMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TDoubleCollection; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectDoubleProcedure; +import gnu.trove.iterator.TObjectDoubleIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and double values. + */ +public interface TObjectDoubleMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + double getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * double value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(double value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the double value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + double get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + double put(K key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + double putIfAbsent(K key, double value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous double value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + double remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,double) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectDoubleMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TDoubleCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TDoubleIterator.remove, + * TDoubleCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of double values. Changes + * to the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of double values. + */ + double[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of double values. + */ + double[] values(double[] array); + + /** + * Returns a TObjectDoubleIterator with access to this map's keys and + * values. + * + * @return a TObjectDoubleIterator with access to this map's keys and + * values. + */ + public TObjectDoubleIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(K key, double adjust_amount, double put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectDoubleProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectFloatMap.java b/src/gnu/trove/map/TObjectFloatMap.java new file mode 100644 index 0000000..d55c068 --- /dev/null +++ b/src/gnu/trove/map/TObjectFloatMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TFloatCollection; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectFloatProcedure; +import gnu.trove.iterator.TObjectFloatIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and float values. + */ +public interface TObjectFloatMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + float getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * float value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(float value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the float value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + float get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + float put(K key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + float putIfAbsent(K key, float value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous float value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + float remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,float) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectFloatMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TFloatCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TFloatIterator.remove, + * TFloatCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of float values. Changes + * to the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of float values. + */ + float[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of float values. + */ + float[] values(float[] array); + + /** + * Returns a TObjectFloatIterator with access to this map's keys and + * values. + * + * @return a TObjectFloatIterator with access to this map's keys and + * values. + */ + public TObjectFloatIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(K key, float adjust_amount, float put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectFloatProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectIntMap.java b/src/gnu/trove/map/TObjectIntMap.java new file mode 100644 index 0000000..a796830 --- /dev/null +++ b/src/gnu/trove/map/TObjectIntMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TIntCollection; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectIntProcedure; +import gnu.trove.iterator.TObjectIntIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and int values. + */ +public interface TObjectIntMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + int getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * int value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(int value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the int value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + int get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + int put(K key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + int putIfAbsent(K key, int value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous int value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + int remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,int) put(k, v)} on this map once for each mapping from key + * k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectIntMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TIntCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TIntIterator.remove, + * TIntCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of int values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of int values. + */ + int[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of int values. + */ + int[] values(int[] array); + + /** + * Returns a TObjectIntIterator with access to this map's keys and + * values. + * + * @return a TObjectIntIterator with access to this map's keys and + * values. + */ + public TObjectIntIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(K key, int adjust_amount, int put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectIntProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectLongMap.java b/src/gnu/trove/map/TObjectLongMap.java new file mode 100644 index 0000000..df3d5d5 --- /dev/null +++ b/src/gnu/trove/map/TObjectLongMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TLongCollection; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectLongProcedure; +import gnu.trove.iterator.TObjectLongIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and long values. + */ +public interface TObjectLongMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + long getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * long value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(long value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the long value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + long get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + long put(K key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + long putIfAbsent(K key, long value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous long value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + long remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,long) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectLongMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TLongCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TLongIterator.remove, + * TLongCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of long values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of long values. + */ + long[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of long values. + */ + long[] values(long[] array); + + /** + * Returns a TObjectLongIterator with access to this map's keys and + * values. + * + * @return a TObjectLongIterator with access to this map's keys and + * values. + */ + public TObjectLongIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(K key, long adjust_amount, long put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectLongProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectShortMap.java b/src/gnu/trove/map/TObjectShortMap.java new file mode 100644 index 0000000..7854985 --- /dev/null +++ b/src/gnu/trove/map/TObjectShortMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TShortCollection; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectShortProcedure; +import gnu.trove.iterator.TObjectShortIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and short values. + */ +public interface TObjectShortMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + short getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * short value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(short value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the short value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + short get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + short put(K key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + short putIfAbsent(K key, short value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous short value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + short remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,short) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectShortMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TShortCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TShortIterator.remove, + * TShortCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of short values. Changes + * to the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of short values. + */ + short[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of short values. + */ + short[] values(short[] array); + + /** + * Returns a TObjectShortIterator with access to this map's keys and + * values. + * + * @return a TObjectShortIterator with access to this map's keys and + * values. + */ + public TObjectShortIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(K key, short adjust_amount, short put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectShortProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TShortByteMap.java b/src/gnu/trove/map/TShortByteMap.java new file mode 100644 index 0000000..a260315 --- /dev/null +++ b/src/gnu/trove/map/TShortByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and byte values. + */ +public interface TShortByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(short key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(short key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortByteIterator with access to this map's keys and values + */ + public TShortByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TShortCharMap.java b/src/gnu/trove/map/TShortCharMap.java new file mode 100644 index 0000000..e483d40 --- /dev/null +++ b/src/gnu/trove/map/TShortCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and char values. + */ +public interface TShortCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(short key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(short key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortCharIterator with access to this map's keys and values + */ + public TShortCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(short key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TShortDoubleMap.java b/src/gnu/trove/map/TShortDoubleMap.java new file mode 100644 index 0000000..8355e11 --- /dev/null +++ b/src/gnu/trove/map/TShortDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and double values. + */ +public interface TShortDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(short key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(short key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortDoubleIterator with access to this map's keys and values + */ + public TShortDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(short key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TShortFloatMap.java b/src/gnu/trove/map/TShortFloatMap.java new file mode 100644 index 0000000..573316f --- /dev/null +++ b/src/gnu/trove/map/TShortFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and float values. + */ +public interface TShortFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(short key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(short key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortFloatIterator with access to this map's keys and values + */ + public TShortFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(short key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TShortIntMap.java b/src/gnu/trove/map/TShortIntMap.java new file mode 100644 index 0000000..5c089b5 --- /dev/null +++ b/src/gnu/trove/map/TShortIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and int values. + */ +public interface TShortIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(short key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(short key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortIntIterator with access to this map's keys and values + */ + public TShortIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(short key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TShortLongMap.java b/src/gnu/trove/map/TShortLongMap.java new file mode 100644 index 0000000..3c33309 --- /dev/null +++ b/src/gnu/trove/map/TShortLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and long values. + */ +public interface TShortLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(short key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(short key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortLongIterator with access to this map's keys and values + */ + public TShortLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(short key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TShortObjectMap.java b/src/gnu/trove/map/TShortObjectMap.java new file mode 100644 index 0000000..0830bef --- /dev/null +++ b/src/gnu/trove/map/TShortObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TShortObjectIterator; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TShortObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TShortSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of short keys and Object values. + */ +public interface TShortObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + short getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(short key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the short value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(short key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(short) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(short key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(short key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous short value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(short key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(short,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TShortObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TShortSet} view of the keys contained in this map. The set + * is backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TShortSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + short[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + short[] keys(short[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of short values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of short values. + */ + V[] values(V[] array); + + /** + * Returns a TShortObjectIterator with access to this map's keys and + * values. + * + * @return a TShortObjectIterator with access to this map's keys and + * values. + */ + public TShortObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TShortObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TShortShortMap.java b/src/gnu/trove/map/TShortShortMap.java new file mode 100644 index 0000000..a4603ce --- /dev/null +++ b/src/gnu/trove/map/TShortShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and short values. + */ +public interface TShortShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(short key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(short key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortShortIterator with access to this map's keys and values + */ + public TShortShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(short key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/custom_hash/TObjectByteCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectByteCustomHashMap.java new file mode 100644 index 0000000..c0f7ce3 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectByteCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TByteCollection; +import gnu.trove.function.TByteFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.iterator.TObjectByteIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectByteMap; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and byte values. + * + * @author Rob Eden + */ +public class TObjectByteCustomHashMap extends TCustomObjectHash implements TObjectByteMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectByteProcedure PUT_ALL_PROC = new TObjectByteProcedure() { + @Override + public boolean execute(K key, byte value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient byte[] _values; + + /** the value that represents null */ + protected byte no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectByteCustomHashMap() { + } + + /** + * Creates a new TObjectByteHashMap instance with the default + * capacity and load factor. + */ + public TObjectByteCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + byte noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectByteCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectByteMap to be copied. + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, TObjectByteMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectByteCustomHashMap) { + TObjectByteCustomHashMap hashmap = (TObjectByteCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + byte oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new byte[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + Object[] keys = _set; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public byte get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public byte put(K key, byte value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(K key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private byte doPut(byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public byte remove(Object key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectByteMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TByteValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectByteIterator iterator() { + return new TObjectByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(final K key, final byte adjust_amount, final byte put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + @Override + public void transformValues(TByteFunction function) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectByteMap)) { + return false; + } + TObjectByteMap that = (TObjectByteMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectByteIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + byte value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectByteCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectByteCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectByteCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectByteCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectByteCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectByteCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TByteValueCollection implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TObjectByteValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TObjectByteCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TObjectByteCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TObjectByteCustomHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TObjectByteCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectByteCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TObjectByteCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectByteCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TObjectByteCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectByteValueHashIterator implements TByteIterator { + + protected THash _hash = TObjectByteCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectByteValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectByteCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectByteCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectByteHashIterator extends TObjectHashIterator implements TObjectByteIterator { + + /** the collection being iterated over */ + private final TObjectByteCustomHashMap _map; + + public TObjectByteHashIterator(TObjectByteCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeByte(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + byte val = in.readByte(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, byte value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectCharCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectCharCustomHashMap.java new file mode 100644 index 0000000..5c223e0 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectCharCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TCharCollection; +import gnu.trove.function.TCharFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.iterator.TObjectCharIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectCharMap; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and char values. + * + * @author Rob Eden + */ +public class TObjectCharCustomHashMap extends TCustomObjectHash implements TObjectCharMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectCharProcedure PUT_ALL_PROC = new TObjectCharProcedure() { + @Override + public boolean execute(K key, char value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient char[] _values; + + /** the value that represents null */ + protected char no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectCharCustomHashMap() { + } + + /** + * Creates a new TObjectCharHashMap instance with the default + * capacity and load factor. + */ + public TObjectCharCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + char noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectCharCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectCharMap to be copied. + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, TObjectCharMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectCharCustomHashMap) { + TObjectCharCustomHashMap hashmap = (TObjectCharCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + char oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new char[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + Object[] keys = _set; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public char get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public char put(K key, char value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(K key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private char doPut(char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public char remove(Object key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectCharMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TCharValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectCharIterator iterator() { + return new TObjectCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(final K key, final char adjust_amount, final char put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + @Override + public void transformValues(TCharFunction function) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectCharMap)) { + return false; + } + TObjectCharMap that = (TObjectCharMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectCharIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + char value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectCharCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectCharCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectCharCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectCharCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectCharCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectCharCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TCharValueCollection implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TObjectCharValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TObjectCharCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TObjectCharCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TObjectCharCustomHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TObjectCharCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectCharCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TObjectCharCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectCharCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TObjectCharCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectCharValueHashIterator implements TCharIterator { + + protected THash _hash = TObjectCharCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectCharValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectCharCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectCharCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectCharHashIterator extends TObjectHashIterator implements TObjectCharIterator { + + /** the collection being iterated over */ + private final TObjectCharCustomHashMap _map; + + public TObjectCharHashIterator(TObjectCharCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeChar(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + char val = in.readChar(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, char value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectDoubleCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectDoubleCustomHashMap.java new file mode 100644 index 0000000..8338f2d --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectDoubleCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TDoubleCollection; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.iterator.TObjectDoubleIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectDoubleMap; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and double values. + * + * @author Rob Eden + */ +public class TObjectDoubleCustomHashMap extends TCustomObjectHash implements TObjectDoubleMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectDoubleProcedure PUT_ALL_PROC = new TObjectDoubleProcedure() { + @Override + public boolean execute(K key, double value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient double[] _values; + + /** the value that represents null */ + protected double no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectDoubleCustomHashMap() { + } + + /** + * Creates a new TObjectDoubleHashMap instance with the default + * capacity and load factor. + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime value + * at or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + double noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectDoubleCustomHashMap that contains the + * entries in the map passed to it. + * + * @param map + * the TObjectDoubleMap to be copied. + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, TObjectDoubleMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectDoubleCustomHashMap) { + TObjectDoubleCustomHashMap hashmap = (TObjectDoubleCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + double oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new double[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + Object[] keys = _set; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public double get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public double put(K key, double value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(K key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private double doPut(double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public double remove(Object key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectDoubleMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TDoubleValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectDoubleIterator iterator() { + return new TObjectDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(final K key, final double adjust_amount, final double put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + @Override + public void transformValues(TDoubleFunction function) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectDoubleMap)) { + return false; + } + TObjectDoubleMap that = (TObjectDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectDoubleIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + double value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectDoubleCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectDoubleCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectDoubleCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectDoubleCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectDoubleCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectDoubleCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TDoubleValueCollection implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TObjectDoubleValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TObjectDoubleCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TObjectDoubleCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TObjectDoubleCustomHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TObjectDoubleCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectDoubleCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TObjectDoubleCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectDoubleCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TObjectDoubleCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectDoubleValueHashIterator implements TDoubleIterator { + + protected THash _hash = TObjectDoubleCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectDoubleValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectDoubleCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectDoubleCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectDoubleHashIterator extends TObjectHashIterator implements TObjectDoubleIterator { + + /** the collection being iterated over */ + private final TObjectDoubleCustomHashMap _map; + + public TObjectDoubleHashIterator(TObjectDoubleCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + double val = in.readDouble(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, double value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectFloatCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectFloatCustomHashMap.java new file mode 100644 index 0000000..e2ae1e5 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectFloatCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TFloatCollection; +import gnu.trove.function.TFloatFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.iterator.TObjectFloatIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectFloatMap; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and float values. + * + * @author Rob Eden + */ +public class TObjectFloatCustomHashMap extends TCustomObjectHash implements TObjectFloatMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectFloatProcedure PUT_ALL_PROC = new TObjectFloatProcedure() { + @Override + public boolean execute(K key, float value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient float[] _values; + + /** the value that represents null */ + protected float no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectFloatCustomHashMap() { + } + + /** + * Creates a new TObjectFloatHashMap instance with the default + * capacity and load factor. + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + float noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectFloatCustomHashMap that contains the + * entries in the map passed to it. + * + * @param map + * the TObjectFloatMap to be copied. + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, TObjectFloatMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectFloatCustomHashMap) { + TObjectFloatCustomHashMap hashmap = (TObjectFloatCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + float oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new float[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + Object[] keys = _set; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public float get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public float put(K key, float value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(K key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private float doPut(float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public float remove(Object key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectFloatMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TFloatValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectFloatIterator iterator() { + return new TObjectFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(final K key, final float adjust_amount, final float put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + @Override + public void transformValues(TFloatFunction function) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectFloatMap)) { + return false; + } + TObjectFloatMap that = (TObjectFloatMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectFloatIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + float value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectFloatCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectFloatCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectFloatCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectFloatCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectFloatCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectFloatCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TFloatValueCollection implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TObjectFloatValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TObjectFloatCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TObjectFloatCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TObjectFloatCustomHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TObjectFloatCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectFloatCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TObjectFloatCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectFloatCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TObjectFloatCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectFloatValueHashIterator implements TFloatIterator { + + protected THash _hash = TObjectFloatCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectFloatValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectFloatCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectFloatCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectFloatHashIterator extends TObjectHashIterator implements TObjectFloatIterator { + + /** the collection being iterated over */ + private final TObjectFloatCustomHashMap _map; + + public TObjectFloatHashIterator(TObjectFloatCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + float val = in.readFloat(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, float value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectIntCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectIntCustomHashMap.java new file mode 100644 index 0000000..f288c19 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectIntCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TIntCollection; +import gnu.trove.function.TIntFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.TObjectIntIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and int values. + * + * @author Rob Eden + */ +public class TObjectIntCustomHashMap extends TCustomObjectHash implements TObjectIntMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectIntProcedure PUT_ALL_PROC = new TObjectIntProcedure() { + @Override + public boolean execute(K key, int value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient int[] _values; + + /** the value that represents null */ + protected int no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectIntCustomHashMap() { + } + + /** + * Creates a new TObjectIntHashMap instance with the default + * capacity and load factor. + */ + public TObjectIntCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + int noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectIntCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectIntMap to be copied. + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, TObjectIntMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectIntCustomHashMap) { + TObjectIntCustomHashMap hashmap = (TObjectIntCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + int oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new int[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + Object[] keys = _set; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public int get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public int put(K key, int value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(K key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private int doPut(int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public int remove(Object key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectIntMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TIntValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectIntIterator iterator() { + return new TObjectIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(final K key, final int adjust_amount, final int put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + @Override + public void transformValues(TIntFunction function) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectIntMap)) { + return false; + } + TObjectIntMap that = (TObjectIntMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectIntIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + int value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectIntCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectIntCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectIntCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectIntCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectIntCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectIntCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TIntValueCollection implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TObjectIntValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TObjectIntCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TObjectIntCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TObjectIntCustomHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TObjectIntCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectIntCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TObjectIntCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectIntCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TObjectIntCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectIntValueHashIterator implements TIntIterator { + + protected THash _hash = TObjectIntCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectIntValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectIntCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectIntCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectIntHashIterator extends TObjectHashIterator implements TObjectIntIterator { + + /** the collection being iterated over */ + private final TObjectIntCustomHashMap _map; + + public TObjectIntHashIterator(TObjectIntCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeInt(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + int val = in.readInt(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, int value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectLongCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectLongCustomHashMap.java new file mode 100644 index 0000000..817461f --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectLongCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TLongCollection; +import gnu.trove.function.TLongFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.iterator.TObjectLongIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectLongMap; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and long values. + * + * @author Rob Eden + */ +public class TObjectLongCustomHashMap extends TCustomObjectHash implements TObjectLongMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectLongProcedure PUT_ALL_PROC = new TObjectLongProcedure() { + @Override + public boolean execute(K key, long value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient long[] _values; + + /** the value that represents null */ + protected long no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectLongCustomHashMap() { + } + + /** + * Creates a new TObjectLongHashMap instance with the default + * capacity and load factor. + */ + public TObjectLongCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + long noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectLongCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectLongMap to be copied. + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, TObjectLongMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectLongCustomHashMap) { + TObjectLongCustomHashMap hashmap = (TObjectLongCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + long oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new long[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + Object[] keys = _set; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public long get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public long put(K key, long value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(K key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private long doPut(long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public long remove(Object key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectLongMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TLongValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectLongIterator iterator() { + return new TObjectLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(final K key, final long adjust_amount, final long put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + @Override + public void transformValues(TLongFunction function) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectLongMap)) { + return false; + } + TObjectLongMap that = (TObjectLongMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectLongIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + long value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectLongCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectLongCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectLongCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectLongCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectLongCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectLongCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TLongValueCollection implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TObjectLongValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TObjectLongCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TObjectLongCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TObjectLongCustomHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TObjectLongCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectLongCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TObjectLongCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectLongCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TObjectLongCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectLongValueHashIterator implements TLongIterator { + + protected THash _hash = TObjectLongCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectLongValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectLongCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectLongCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectLongHashIterator extends TObjectHashIterator implements TObjectLongIterator { + + /** the collection being iterated over */ + private final TObjectLongCustomHashMap _map; + + public TObjectLongHashIterator(TObjectLongCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeLong(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + long val = in.readLong(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, long value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectShortCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectShortCustomHashMap.java new file mode 100644 index 0000000..ce12258 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectShortCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TShortCollection; +import gnu.trove.function.TShortFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.iterator.TObjectShortIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectShortMap; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and short values. + * + * @author Rob Eden + */ +public class TObjectShortCustomHashMap extends TCustomObjectHash implements TObjectShortMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectShortProcedure PUT_ALL_PROC = new TObjectShortProcedure() { + @Override + public boolean execute(K key, short value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient short[] _values; + + /** the value that represents null */ + protected short no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectShortCustomHashMap() { + } + + /** + * Creates a new TObjectShortHashMap instance with the default + * capacity and load factor. + */ + public TObjectShortCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + short noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectShortCustomHashMap that contains the + * entries in the map passed to it. + * + * @param map + * the TObjectShortMap to be copied. + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, TObjectShortMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectShortCustomHashMap) { + TObjectShortCustomHashMap hashmap = (TObjectShortCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + short oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new short[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + Object[] keys = _set; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public short get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public short put(K key, short value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(K key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private short doPut(short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public short remove(Object key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectShortMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TShortValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectShortIterator iterator() { + return new TObjectShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(final K key, final short adjust_amount, final short put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + @Override + public void transformValues(TShortFunction function) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectShortMap)) { + return false; + } + TObjectShortMap that = (TObjectShortMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectShortIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + short value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectShortCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectShortCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectShortCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectShortCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectShortCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectShortCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TShortValueCollection implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TObjectShortValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TObjectShortCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TObjectShortCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TObjectShortCustomHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TObjectShortCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectShortCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TObjectShortCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectShortCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TObjectShortCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectShortValueHashIterator implements TShortIterator { + + protected THash _hash = TObjectShortCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectShortValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectShortCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectShortCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectShortHashIterator extends TObjectHashIterator implements TObjectShortIterator { + + /** the collection being iterated over */ + private final TObjectShortCustomHashMap _map; + + public TObjectShortHashIterator(TObjectShortCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeShort(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + short val = in.readShort(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, short value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/hash/TByteByteHashMap.java b/src/gnu/trove/map/hash/TByteByteHashMap.java new file mode 100644 index 0000000..33daee6 --- /dev/null +++ b/src/gnu/trove/map/hash/TByteByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteByteHashMap extends TByteByteHash implements TByteByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TByteByteHashMap instance with the default + * capacity and load factor. + */ + public TByteByteHashMap() { + super(); + } + + /** + * Creates a new TByteByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TByteByteHashMap(int initialCapacity, float loadFactor, byte noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TByteByteHashMap(byte[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteByteMap that will be duplicated. + */ + public TByteByteHashMap(TByteByteMap map) { + super(map.size()); + if (map instanceof TByteByteHashMap) { + TByteByteHashMap hashmap = (TByteByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(byte key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(byte key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(byte key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteByteMap map) { + ensureCapacity(map.size()); + TByteByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(byte key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteByteIterator iterator() { + return new TByteByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteByteProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteByteKeyHashIterator(TByteByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteByteValueHashIterator(TByteByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteByteKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteByteHashIterator extends THashPrimitiveIterator implements TByteByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteByteHashMap we will be iterating over. + */ + TByteByteHashIterator(TByteByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteByteMap)) { + return false; + } + TByteByteMap that = (TByteByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + byte val = in.readByte(); + put(key, val); + } + } +} // TByteByteHashMap diff --git a/src/gnu/trove/map/hash/TByteCharHashMap.java b/src/gnu/trove/map/hash/TByteCharHashMap.java new file mode 100644 index 0000000..d1e794b --- /dev/null +++ b/src/gnu/trove/map/hash/TByteCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteCharHashMap extends TByteCharHash implements TByteCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TByteCharHashMap instance with the default + * capacity and load factor. + */ + public TByteCharHashMap() { + super(); + } + + /** + * Creates a new TByteCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TByteCharHashMap(int initialCapacity, float loadFactor, byte noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TByteCharHashMap(byte[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteCharMap that will be duplicated. + */ + public TByteCharHashMap(TByteCharMap map) { + super(map.size()); + if (map instanceof TByteCharHashMap) { + TByteCharHashMap hashmap = (TByteCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(byte key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(byte key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(byte key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteCharMap map) { + ensureCapacity(map.size()); + TByteCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(byte key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteCharIterator iterator() { + return new TByteCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteCharProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteCharKeyHashIterator(TByteCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TByteCharValueHashIterator(TByteCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TByteCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TByteCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TByteCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TByteCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TByteCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TByteCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteCharKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteCharHashIterator extends THashPrimitiveIterator implements TByteCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteCharHashMap we will be iterating over. + */ + TByteCharHashIterator(TByteCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteCharMap)) { + return false; + } + TByteCharMap that = (TByteCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + char val = in.readChar(); + put(key, val); + } + } +} // TByteCharHashMap diff --git a/src/gnu/trove/map/hash/TByteDoubleHashMap.java b/src/gnu/trove/map/hash/TByteDoubleHashMap.java new file mode 100644 index 0000000..dfbc74f --- /dev/null +++ b/src/gnu/trove/map/hash/TByteDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteDoubleHashMap extends TByteDoubleHash implements TByteDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TByteDoubleHashMap instance with the default + * capacity and load factor. + */ + public TByteDoubleHashMap() { + super(); + } + + /** + * Creates a new TByteDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TByteDoubleHashMap(int initialCapacity, float loadFactor, byte noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TByteDoubleHashMap(byte[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteDoubleMap that will be duplicated. + */ + public TByteDoubleHashMap(TByteDoubleMap map) { + super(map.size()); + if (map instanceof TByteDoubleHashMap) { + TByteDoubleHashMap hashmap = (TByteDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(byte key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(byte key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(byte key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteDoubleMap map) { + ensureCapacity(map.size()); + TByteDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(byte key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteDoubleIterator iterator() { + return new TByteDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteDoubleProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteDoubleKeyHashIterator(TByteDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TByteDoubleValueHashIterator(TByteDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TByteDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TByteDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TByteDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TByteDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TByteDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TByteDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteDoubleKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteDoubleHashIterator extends THashPrimitiveIterator implements TByteDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteDoubleHashMap we will be iterating over. + */ + TByteDoubleHashIterator(TByteDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteDoubleMap)) { + return false; + } + TByteDoubleMap that = (TByteDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + double val = in.readDouble(); + put(key, val); + } + } +} // TByteDoubleHashMap diff --git a/src/gnu/trove/map/hash/TByteFloatHashMap.java b/src/gnu/trove/map/hash/TByteFloatHashMap.java new file mode 100644 index 0000000..0acb1aa --- /dev/null +++ b/src/gnu/trove/map/hash/TByteFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteFloatHashMap extends TByteFloatHash implements TByteFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TByteFloatHashMap instance with the default + * capacity and load factor. + */ + public TByteFloatHashMap() { + super(); + } + + /** + * Creates a new TByteFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TByteFloatHashMap(int initialCapacity, float loadFactor, byte noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TByteFloatHashMap(byte[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteFloatMap that will be duplicated. + */ + public TByteFloatHashMap(TByteFloatMap map) { + super(map.size()); + if (map instanceof TByteFloatHashMap) { + TByteFloatHashMap hashmap = (TByteFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(byte key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(byte key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(byte key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteFloatMap map) { + ensureCapacity(map.size()); + TByteFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(byte key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteFloatIterator iterator() { + return new TByteFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteFloatProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteFloatKeyHashIterator(TByteFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TByteFloatValueHashIterator(TByteFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TByteFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TByteFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TByteFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TByteFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TByteFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TByteFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteFloatKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteFloatHashIterator extends THashPrimitiveIterator implements TByteFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteFloatHashMap we will be iterating over. + */ + TByteFloatHashIterator(TByteFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteFloatMap)) { + return false; + } + TByteFloatMap that = (TByteFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + float val = in.readFloat(); + put(key, val); + } + } +} // TByteFloatHashMap diff --git a/src/gnu/trove/map/hash/TByteIntHashMap.java b/src/gnu/trove/map/hash/TByteIntHashMap.java new file mode 100644 index 0000000..2214713 --- /dev/null +++ b/src/gnu/trove/map/hash/TByteIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteIntHashMap extends TByteIntHash implements TByteIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TByteIntHashMap instance with the default capacity + * and load factor. + */ + public TByteIntHashMap() { + super(); + } + + /** + * Creates a new TByteIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TByteIntHashMap(int initialCapacity, float loadFactor, byte noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TByteIntHashMap(byte[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteIntMap that will be duplicated. + */ + public TByteIntHashMap(TByteIntMap map) { + super(map.size()); + if (map instanceof TByteIntHashMap) { + TByteIntHashMap hashmap = (TByteIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(byte key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(byte key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(byte key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteIntMap map) { + ensureCapacity(map.size()); + TByteIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(byte key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteIntIterator iterator() { + return new TByteIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteIntProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteIntKeyHashIterator(TByteIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TByteIntValueHashIterator(TByteIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TByteIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TByteIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TByteIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TByteIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TByteIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TByteIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteIntKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteIntHashIterator extends THashPrimitiveIterator implements TByteIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteIntHashMap we will be iterating over. + */ + TByteIntHashIterator(TByteIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteIntMap)) { + return false; + } + TByteIntMap that = (TByteIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + int val = in.readInt(); + put(key, val); + } + } +} // TByteIntHashMap diff --git a/src/gnu/trove/map/hash/TByteLongHashMap.java b/src/gnu/trove/map/hash/TByteLongHashMap.java new file mode 100644 index 0000000..9ad543e --- /dev/null +++ b/src/gnu/trove/map/hash/TByteLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteLongHashMap extends TByteLongHash implements TByteLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TByteLongHashMap instance with the default + * capacity and load factor. + */ + public TByteLongHashMap() { + super(); + } + + /** + * Creates a new TByteLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TByteLongHashMap(int initialCapacity, float loadFactor, byte noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TByteLongHashMap(byte[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteLongMap that will be duplicated. + */ + public TByteLongHashMap(TByteLongMap map) { + super(map.size()); + if (map instanceof TByteLongHashMap) { + TByteLongHashMap hashmap = (TByteLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(byte key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(byte key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(byte key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteLongMap map) { + ensureCapacity(map.size()); + TByteLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(byte key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteLongIterator iterator() { + return new TByteLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteLongProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteLongKeyHashIterator(TByteLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TByteLongValueHashIterator(TByteLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TByteLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TByteLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TByteLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TByteLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TByteLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TByteLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteLongKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteLongHashIterator extends THashPrimitiveIterator implements TByteLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteLongHashMap we will be iterating over. + */ + TByteLongHashIterator(TByteLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteLongMap)) { + return false; + } + TByteLongMap that = (TByteLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + long val = in.readLong(); + put(key, val); + } + } +} // TByteLongHashMap diff --git a/src/gnu/trove/map/hash/TByteObjectHashMap.java b/src/gnu/trove/map/hash/TByteObjectHashMap.java new file mode 100644 index 0000000..7534c4c --- /dev/null +++ b/src/gnu/trove/map/hash/TByteObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TByteObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TByteObjectProcedure; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.iterator.TByteObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TByteSet; +import gnu.trove.TByteCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for byte keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TByteObjectHashMap extends TByteHash implements TByteObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TByteObjectProcedure PUT_ALL_PROC = new TByteObjectProcedure() { + @Override + public boolean execute(byte key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected byte no_entry_key; + + /** + * Creates a new TByteObjectHashMap instance with the default + * capacity and load factor. + */ + public TByteObjectHashMap() { + super(); + } + + /** + * Creates a new TByteObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TByteObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TByteObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TByteObjectHashMap(int initialCapacity, float loadFactor, byte noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TByteObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TByteObjectMap to be copied. + */ + public TByteObjectHashMap(TByteObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public byte getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(byte key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(byte key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(byte key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(byte key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public byte[] keys() { + byte[] keys = new byte[size()]; + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public byte[] keys(byte[] dest) { + if (dest.length < _size) { + dest = new byte[_size]; + } + + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TByteObjectIterator iterator() { + return new TByteObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TByteObjectProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TByteObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteObjectMap)) { + return false; + } + TByteObjectMap that = (TByteObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TByteObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + byte key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteHashIterator(TByteObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return null != TByteObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TByteObjectHashMap.this.containsKey(((Byte) element).byteValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + if (collection == this) { + return true; + } + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TByteHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** the collection on which the iterator operates */ + private final TByteHash _hash; + + /** {@inheritDoc} */ + public TByteHashIterator(TByteHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TByteObjectValueHashIterator(TByteObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TByteObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TByteObjectHashMap _map; + + public TByteObjectValueHashIterator(TByteObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TByteObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TByteObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TByteObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TByteObjectHashIterator extends THashPrimitiveIterator implements TByteObjectIterator { + + /** the collection being iterated over */ + private final TByteObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TByteObjectHashIterator(TByteObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TByteObjectHashMap diff --git a/src/gnu/trove/map/hash/TByteShortHashMap.java b/src/gnu/trove/map/hash/TByteShortHashMap.java new file mode 100644 index 0000000..770ff1d --- /dev/null +++ b/src/gnu/trove/map/hash/TByteShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteShortHashMap extends TByteShortHash implements TByteShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TByteShortHashMap instance with the default + * capacity and load factor. + */ + public TByteShortHashMap() { + super(); + } + + /** + * Creates a new TByteShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TByteShortHashMap(int initialCapacity, float loadFactor, byte noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TByteShortHashMap(byte[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteShortMap that will be duplicated. + */ + public TByteShortHashMap(TByteShortMap map) { + super(map.size()); + if (map instanceof TByteShortHashMap) { + TByteShortHashMap hashmap = (TByteShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(byte key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(byte key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(byte key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteShortMap map) { + ensureCapacity(map.size()); + TByteShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(byte key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteShortIterator iterator() { + return new TByteShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteShortProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteShortKeyHashIterator(TByteShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TByteShortValueHashIterator(TByteShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TByteShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TByteShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TByteShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TByteShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TByteShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TByteShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteShortKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteShortHashIterator extends THashPrimitiveIterator implements TByteShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteShortHashMap we will be iterating over. + */ + TByteShortHashIterator(TByteShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteShortMap)) { + return false; + } + TByteShortMap that = (TByteShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + short val = in.readShort(); + put(key, val); + } + } +} // TByteShortHashMap diff --git a/src/gnu/trove/map/hash/TCharByteHashMap.java b/src/gnu/trove/map/hash/TCharByteHashMap.java new file mode 100644 index 0000000..178d6c8 --- /dev/null +++ b/src/gnu/trove/map/hash/TCharByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharByteHashMap extends TCharByteHash implements TCharByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TCharByteHashMap instance with the default + * capacity and load factor. + */ + public TCharByteHashMap() { + super(); + } + + /** + * Creates a new TCharByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TCharByteHashMap(int initialCapacity, float loadFactor, char noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TCharByteHashMap(char[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharByteMap that will be duplicated. + */ + public TCharByteHashMap(TCharByteMap map) { + super(map.size()); + if (map instanceof TCharByteHashMap) { + TCharByteHashMap hashmap = (TCharByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(char key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(char key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(char key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharByteMap map) { + ensureCapacity(map.size()); + TCharByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(char key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharByteIterator iterator() { + return new TCharByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharByteProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharByteKeyHashIterator(TCharByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TCharByteValueHashIterator(TCharByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TCharByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TCharByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TCharByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TCharByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TCharByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TCharByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharByteKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharByteHashIterator extends THashPrimitiveIterator implements TCharByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharByteHashMap we will be iterating over. + */ + TCharByteHashIterator(TCharByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharByteMap)) { + return false; + } + TCharByteMap that = (TCharByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + byte val = in.readByte(); + put(key, val); + } + } +} // TCharByteHashMap diff --git a/src/gnu/trove/map/hash/TCharCharHashMap.java b/src/gnu/trove/map/hash/TCharCharHashMap.java new file mode 100644 index 0000000..ad900bf --- /dev/null +++ b/src/gnu/trove/map/hash/TCharCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharCharHashMap extends TCharCharHash implements TCharCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TCharCharHashMap instance with the default + * capacity and load factor. + */ + public TCharCharHashMap() { + super(); + } + + /** + * Creates a new TCharCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TCharCharHashMap(int initialCapacity, float loadFactor, char noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TCharCharHashMap(char[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharCharMap that will be duplicated. + */ + public TCharCharHashMap(TCharCharMap map) { + super(map.size()); + if (map instanceof TCharCharHashMap) { + TCharCharHashMap hashmap = (TCharCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(char key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(char key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(char key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharCharMap map) { + ensureCapacity(map.size()); + TCharCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(char key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharCharIterator iterator() { + return new TCharCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharCharProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(char key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharCharKeyHashIterator(TCharCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharCharValueHashIterator(TCharCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharCharKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharCharHashIterator extends THashPrimitiveIterator implements TCharCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharCharHashMap we will be iterating over. + */ + TCharCharHashIterator(TCharCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharCharMap)) { + return false; + } + TCharCharMap that = (TCharCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + char val = in.readChar(); + put(key, val); + } + } +} // TCharCharHashMap diff --git a/src/gnu/trove/map/hash/TCharDoubleHashMap.java b/src/gnu/trove/map/hash/TCharDoubleHashMap.java new file mode 100644 index 0000000..c0ab81e --- /dev/null +++ b/src/gnu/trove/map/hash/TCharDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharDoubleHashMap extends TCharDoubleHash implements TCharDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TCharDoubleHashMap instance with the default + * capacity and load factor. + */ + public TCharDoubleHashMap() { + super(); + } + + /** + * Creates a new TCharDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TCharDoubleHashMap(int initialCapacity, float loadFactor, char noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TCharDoubleHashMap(char[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharDoubleMap that will be duplicated. + */ + public TCharDoubleHashMap(TCharDoubleMap map) { + super(map.size()); + if (map instanceof TCharDoubleHashMap) { + TCharDoubleHashMap hashmap = (TCharDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(char key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(char key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(char key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharDoubleMap map) { + ensureCapacity(map.size()); + TCharDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(char key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharDoubleIterator iterator() { + return new TCharDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharDoubleProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(char key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharDoubleKeyHashIterator(TCharDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TCharDoubleValueHashIterator(TCharDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TCharDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TCharDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TCharDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TCharDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TCharDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TCharDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharDoubleKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharDoubleHashIterator extends THashPrimitiveIterator implements TCharDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharDoubleHashMap we will be iterating over. + */ + TCharDoubleHashIterator(TCharDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharDoubleMap)) { + return false; + } + TCharDoubleMap that = (TCharDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + double val = in.readDouble(); + put(key, val); + } + } +} // TCharDoubleHashMap diff --git a/src/gnu/trove/map/hash/TCharFloatHashMap.java b/src/gnu/trove/map/hash/TCharFloatHashMap.java new file mode 100644 index 0000000..914ae0b --- /dev/null +++ b/src/gnu/trove/map/hash/TCharFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharFloatHashMap extends TCharFloatHash implements TCharFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TCharFloatHashMap instance with the default + * capacity and load factor. + */ + public TCharFloatHashMap() { + super(); + } + + /** + * Creates a new TCharFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TCharFloatHashMap(int initialCapacity, float loadFactor, char noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TCharFloatHashMap(char[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharFloatMap that will be duplicated. + */ + public TCharFloatHashMap(TCharFloatMap map) { + super(map.size()); + if (map instanceof TCharFloatHashMap) { + TCharFloatHashMap hashmap = (TCharFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(char key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(char key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(char key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharFloatMap map) { + ensureCapacity(map.size()); + TCharFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(char key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharFloatIterator iterator() { + return new TCharFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharFloatProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(char key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharFloatKeyHashIterator(TCharFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TCharFloatValueHashIterator(TCharFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TCharFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TCharFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TCharFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TCharFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TCharFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TCharFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharFloatKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharFloatHashIterator extends THashPrimitiveIterator implements TCharFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharFloatHashMap we will be iterating over. + */ + TCharFloatHashIterator(TCharFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharFloatMap)) { + return false; + } + TCharFloatMap that = (TCharFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + float val = in.readFloat(); + put(key, val); + } + } +} // TCharFloatHashMap diff --git a/src/gnu/trove/map/hash/TCharIntHashMap.java b/src/gnu/trove/map/hash/TCharIntHashMap.java new file mode 100644 index 0000000..adf0dde --- /dev/null +++ b/src/gnu/trove/map/hash/TCharIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharIntHashMap extends TCharIntHash implements TCharIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TCharIntHashMap instance with the default capacity + * and load factor. + */ + public TCharIntHashMap() { + super(); + } + + /** + * Creates a new TCharIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TCharIntHashMap(int initialCapacity, float loadFactor, char noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TCharIntHashMap(char[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharIntMap that will be duplicated. + */ + public TCharIntHashMap(TCharIntMap map) { + super(map.size()); + if (map instanceof TCharIntHashMap) { + TCharIntHashMap hashmap = (TCharIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(char key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(char key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(char key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharIntMap map) { + ensureCapacity(map.size()); + TCharIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(char key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharIntIterator iterator() { + return new TCharIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharIntProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(char key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharIntKeyHashIterator(TCharIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TCharIntValueHashIterator(TCharIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TCharIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TCharIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TCharIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TCharIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TCharIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TCharIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharIntKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharIntHashIterator extends THashPrimitiveIterator implements TCharIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharIntHashMap we will be iterating over. + */ + TCharIntHashIterator(TCharIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharIntMap)) { + return false; + } + TCharIntMap that = (TCharIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + int val = in.readInt(); + put(key, val); + } + } +} // TCharIntHashMap diff --git a/src/gnu/trove/map/hash/TCharLongHashMap.java b/src/gnu/trove/map/hash/TCharLongHashMap.java new file mode 100644 index 0000000..f52070f --- /dev/null +++ b/src/gnu/trove/map/hash/TCharLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharLongHashMap extends TCharLongHash implements TCharLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TCharLongHashMap instance with the default + * capacity and load factor. + */ + public TCharLongHashMap() { + super(); + } + + /** + * Creates a new TCharLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TCharLongHashMap(int initialCapacity, float loadFactor, char noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TCharLongHashMap(char[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharLongMap that will be duplicated. + */ + public TCharLongHashMap(TCharLongMap map) { + super(map.size()); + if (map instanceof TCharLongHashMap) { + TCharLongHashMap hashmap = (TCharLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(char key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(char key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(char key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharLongMap map) { + ensureCapacity(map.size()); + TCharLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(char key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharLongIterator iterator() { + return new TCharLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharLongProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(char key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharLongKeyHashIterator(TCharLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TCharLongValueHashIterator(TCharLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TCharLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TCharLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TCharLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TCharLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TCharLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TCharLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharLongKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharLongHashIterator extends THashPrimitiveIterator implements TCharLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharLongHashMap we will be iterating over. + */ + TCharLongHashIterator(TCharLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharLongMap)) { + return false; + } + TCharLongMap that = (TCharLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + long val = in.readLong(); + put(key, val); + } + } +} // TCharLongHashMap diff --git a/src/gnu/trove/map/hash/TCharObjectHashMap.java b/src/gnu/trove/map/hash/TCharObjectHashMap.java new file mode 100644 index 0000000..eef81e1 --- /dev/null +++ b/src/gnu/trove/map/hash/TCharObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TCharObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TCharObjectProcedure; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.iterator.TCharObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TCharSet; +import gnu.trove.TCharCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for char keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TCharObjectHashMap extends TCharHash implements TCharObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TCharObjectProcedure PUT_ALL_PROC = new TCharObjectProcedure() { + @Override + public boolean execute(char key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected char no_entry_key; + + /** + * Creates a new TCharObjectHashMap instance with the default + * capacity and load factor. + */ + public TCharObjectHashMap() { + super(); + } + + /** + * Creates a new TCharObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TCharObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TCharObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TCharObjectHashMap(int initialCapacity, float loadFactor, char noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TCharObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TCharObjectMap to be copied. + */ + public TCharObjectHashMap(TCharObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public char getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(char key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(char key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(char key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(char key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public char[] keys() { + char[] keys = new char[size()]; + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public char[] keys(char[] dest) { + if (dest.length < _size) { + dest = new char[_size]; + } + + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TCharObjectIterator iterator() { + return new TCharObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TCharObjectProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TCharObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharObjectMap)) { + return false; + } + TCharObjectMap that = (TCharObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TCharObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + char key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharHashIterator(TCharObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return null != TCharObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TCharObjectHashMap.this.containsKey(((Character) element).charValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + if (collection == this) { + return true; + } + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TCharHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** the collection on which the iterator operates */ + private final TCharHash _hash; + + /** {@inheritDoc} */ + public TCharHashIterator(TCharHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TCharObjectValueHashIterator(TCharObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TCharObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TCharObjectHashMap _map; + + public TCharObjectValueHashIterator(TCharObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TCharObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TCharObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TCharObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TCharObjectHashIterator extends THashPrimitiveIterator implements TCharObjectIterator { + + /** the collection being iterated over */ + private final TCharObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TCharObjectHashIterator(TCharObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TCharObjectHashMap diff --git a/src/gnu/trove/map/hash/TCharShortHashMap.java b/src/gnu/trove/map/hash/TCharShortHashMap.java new file mode 100644 index 0000000..2402cb4 --- /dev/null +++ b/src/gnu/trove/map/hash/TCharShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharShortHashMap extends TCharShortHash implements TCharShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TCharShortHashMap instance with the default + * capacity and load factor. + */ + public TCharShortHashMap() { + super(); + } + + /** + * Creates a new TCharShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TCharShortHashMap(int initialCapacity, float loadFactor, char noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TCharShortHashMap(char[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharShortMap that will be duplicated. + */ + public TCharShortHashMap(TCharShortMap map) { + super(map.size()); + if (map instanceof TCharShortHashMap) { + TCharShortHashMap hashmap = (TCharShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(char key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(char key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(char key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharShortMap map) { + ensureCapacity(map.size()); + TCharShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(char key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharShortIterator iterator() { + return new TCharShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharShortProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(char key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharShortKeyHashIterator(TCharShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TCharShortValueHashIterator(TCharShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TCharShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TCharShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TCharShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TCharShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TCharShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TCharShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharShortKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharShortHashIterator extends THashPrimitiveIterator implements TCharShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharShortHashMap we will be iterating over. + */ + TCharShortHashIterator(TCharShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharShortMap)) { + return false; + } + TCharShortMap that = (TCharShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + short val = in.readShort(); + put(key, val); + } + } +} // TCharShortHashMap diff --git a/src/gnu/trove/map/hash/TCustomHashMap.java b/src/gnu/trove/map/hash/TCustomHashMap.java new file mode 100644 index 0000000..42d8293 --- /dev/null +++ b/src/gnu/trove/map/hash/TCustomHashMap.java @@ -0,0 +1,896 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.function.TObjectFunction; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TMap; +import gnu.trove.procedure.TObjectObjectProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +/** + * An implementation of the Map interface which uses an open addressed hash + * table to store its contents. + * + * @author Rob Eden + */ +public class TCustomHashMap extends TCustomObjectHash implements TMap, Externalizable { + + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient V[] _values; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TCustomHashMap() { + super(); + } + + /** + * Creates a new TCustomHashMap instance with the default capacity + * and load factor. + */ + public TCustomHashMap(HashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new TCustomHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCustomHashMap(HashingStrategy strategy, int initialCapacity) { + super(strategy, initialCapacity); + } + + /** + * Creates a new TCustomHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + } + + /** + * Creates a new TCustomHashMap instance which contains the + * key/value pairs in map. + * + * @param map + * a Map value + */ + public TCustomHashMap(HashingStrategy strategy, Map map) { + + this(strategy, map.size()); + putAll(map); + } + + /** + * Creates a new TCustomHashMap instance which contains the + * key/value pairs in map. + * + * @param map + * a Map value + */ + public TCustomHashMap(HashingStrategy strategy, TCustomHashMap map) { + + this(strategy, map.size()); + putAll(map); + } + + /** + * initialize the value array of the map. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + // noinspection unchecked + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V put(K key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V putIfAbsent(K key, V value) { + int index = insertKey(key); + if (index < 0) { + return _values[-index - 1]; + } + return doPut(value, index); + } + + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + @SuppressWarnings({ "unchecked", "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Map)) { + return false; + } + Map that = (Map) other; + if (that.size() != this.size()) { + return false; + } + return forEachEntry(new EqProcedure(that)); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, V value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + private final class HashProcedure implements TObjectObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(K key, V value) { + h += HashFunctions.hash(key) ^ (value == null ? 0 : value.hashCode()); + return true; + } + } + + private static final class EqProcedure implements TObjectObjectProcedure { + private final Map _otherMap; + + EqProcedure(Map otherMap) { + _otherMap = otherMap; + } + + @Override + public final boolean execute(K key, V value) { + // Check to make sure the key is there. This avoids problems that come up with + // null values. Since it is only caused in that cause, only do this when the + // value is null (to avoid extra work). + if (value == null && !_otherMap.containsKey(key)) { + return false; + } + + V oValue = _otherMap.get(key); + return oValue == value || (oValue != null && oValue.equals(value)); + } + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TObjectObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectObjectProcedure procedure) { + Object[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TObjectObjectProcedure procedure) { + boolean modified = false; + Object[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + @Override + public void transformValues(TObjectFunction function) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + int oldSize = size(); + Object oldKeys[] = _set; + V oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = (V[]) new Object[newCapacity]; + + // Process entries from the old array, skipping free and removed slots. Put the + // values into the appropriate place in the new array. + for (int i = oldCapacity; i-- > 0;) { + Object o = oldKeys[i]; + if (o == FREE || o == REMOVED) + continue; + + int index = insertKey((K) o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldKeys); + } + _values[index] = oldVals[i]; + } + } + + /** + * retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V get(Object key) { + int index = index(key); + if (index < 0 || !strategy.equals((K) _set[index], (K) key)) { + return null; + } + return _values[index]; + } + + /** Empties the map. */ + @Override + public void clear() { + if (size() == 0) { + return; // optimization + } + + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return an Object value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V remove(Object key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * removes the mapping at index from the map. + * + * @param index + * an int value + */ + @Override + public void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + /** + * Returns a view on the values of the map. + * + * @return a Collection value + */ + @Override + public Collection values() { + return new ValueView(); + } + + /** + * returns a Set view on the keys of the map. + * + * @return a Set value + */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new EntryView(); + } + + /** + * checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + Object[] set = _set; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && val == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) + && (val == vals[i] || strategy.equals((K) val, (K) vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** + * checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** + * copies the key/value mappings in map into this map. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof TCustomHashMap + for (Map.Entry e : map.entrySet()) { + put(e.getKey(), e.getValue()); + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TCustomHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + Object[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && value == values[i] + || (null != values[i] && strategy.equals((K) values[i], (K) value))) { + + removeAt(i); + return true; + } + } + + return false; + } + } + + /** a view onto the entries of the map. */ + protected class EntryView extends MapBackedView> { + + private final class EntryIterator extends TObjectHashIterator { + + EntryIterator(TCustomHashMap map) { + super(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Entry objectAtIndex(final int index) { + return new Entry((K) _set[index], _values[index], index); + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator> iterator() { + return new EntryIterator(TCustomHashMap.this); + } + + @Override + public boolean removeElement(Map.Entry entry) { + // have to effectively reimplement Map.remove here + // because we need to return true/false depending on + // whether the removal took place. Since the Entry's + // value can be null, this means that we can't rely + // on the value of the object returned by Map.remove() + // to determine whether a deletion actually happened. + // + // Note also that the deletion is only legal if + // both the key and the value match. + Object val; + int index; + + K key = keyForEntry(entry); + index = index(key); + if (index >= 0) { + val = valueForEntry(entry); + if (val == _values[index] || (null != val && strategy.equals((K) val, (K) _values[index]))) { + removeAt(index); // clear key,state; adjust size + return true; + } + } + return false; + } + + @Override + public boolean containsElement(Map.Entry entry) { + Object val = get(keyForEntry(entry)); + Object entryValue = entry.getValue(); + return entryValue == val || (null != val && strategy.equals((K) val, (K) entryValue)); + } + + protected V valueForEntry(Map.Entry entry) { + return entry.getValue(); + } + + protected K keyForEntry(Map.Entry entry) { + return entry.getKey(); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + // public boolean containsAll( Collection collection ) { + // for ( Object element : collection ) { + // if ( !contains( element ) ) { + // return false; + // } + // } + // return true; + // } + + @Override + public void clear() { + TCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + Iterator i = iterator(); + if (!i.hasNext()) + return "{}"; + + StringBuilder sb = new StringBuilder(); + sb.append('{'); + for (;;) { + E e = i.next(); + sb.append(e == this ? "(this Collection)" : e); + if (!i.hasNext()) + return sb.append('}').toString(); + sb.append(", "); + } + } + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return null != TCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TCustomHashMap.this.contains(key); + } + } + + final class Entry implements Map.Entry { + + private K key; + private V val; + private final int index; + + Entry(final K key, V value, final int index) { + this.key = key; + this.val = value; + this.index = index; + } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public V setValue(V o) { + if (_values[index] != val) { + throw new ConcurrentModificationException(); + } + // need to return previous value + V retval = val; + // update this entry's value, in case setValue is called again + _values[index] = o; + val = o; + return retval; + } + + @Override + public boolean equals(Object o) { + if (o instanceof Map.Entry) { + Map.Entry e1 = this; + Map.Entry e2 = (Map.Entry) o; + return (e1.getKey() == null ? e2.getKey() == null : strategy.equals(e1.getKey(), (K) e2.getKey())) + && (e1.getValue() == null ? e2.getValue() == null : e1.getValue().equals(e2.getValue())); + } + return false; + } + + @Override + public int hashCode() { + return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); + } + + @Override + public String toString() { + return key + "=" + val; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + // noinspection unchecked + V val = (V) in.readObject(); + put(key, val); + } + } +} // TCustomHashMap diff --git a/src/gnu/trove/map/hash/TDoubleByteHashMap.java b/src/gnu/trove/map/hash/TDoubleByteHashMap.java new file mode 100644 index 0000000..1437c73 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleByteHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleByteHashMap extends TDoubleByteHash implements TDoubleByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TDoubleByteHashMap instance with the default + * capacity and load factor. + */ + public TDoubleByteHashMap() { + super(); + } + + /** + * Creates a new TDoubleByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TDoubleByteHashMap(int initialCapacity, float loadFactor, double noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a byte array containing the values. + */ + public TDoubleByteHashMap(double[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleByteMap that will be duplicated. + */ + public TDoubleByteHashMap(TDoubleByteMap map) { + super(map.size()); + if (map instanceof TDoubleByteHashMap) { + TDoubleByteHashMap hashmap = (TDoubleByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(double key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(double key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(double key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleByteMap map) { + ensureCapacity(map.size()); + TDoubleByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(double key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleByteIterator iterator() { + return new TDoubleByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleByteProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleByteKeyHashIterator(TDoubleByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TDoubleByteValueHashIterator(TDoubleByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TDoubleByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TDoubleByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TDoubleByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TDoubleByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TDoubleByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TDoubleByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleByteKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleByteHashIterator extends THashPrimitiveIterator implements TDoubleByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleByteHashMap we will be iterating over. + */ + TDoubleByteHashIterator(TDoubleByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleByteMap)) { + return false; + } + TDoubleByteMap that = (TDoubleByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + byte val = in.readByte(); + put(key, val); + } + } +} // TDoubleByteHashMap diff --git a/src/gnu/trove/map/hash/TDoubleCharHashMap.java b/src/gnu/trove/map/hash/TDoubleCharHashMap.java new file mode 100644 index 0000000..2b0e3f9 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleCharHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleCharHashMap extends TDoubleCharHash implements TDoubleCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TDoubleCharHashMap instance with the default + * capacity and load factor. + */ + public TDoubleCharHashMap() { + super(); + } + + /** + * Creates a new TDoubleCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TDoubleCharHashMap(int initialCapacity, float loadFactor, double noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a char array containing the values. + */ + public TDoubleCharHashMap(double[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleCharMap that will be duplicated. + */ + public TDoubleCharHashMap(TDoubleCharMap map) { + super(map.size()); + if (map instanceof TDoubleCharHashMap) { + TDoubleCharHashMap hashmap = (TDoubleCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(double key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(double key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(double key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleCharMap map) { + ensureCapacity(map.size()); + TDoubleCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(double key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleCharIterator iterator() { + return new TDoubleCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleCharProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(double key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleCharKeyHashIterator(TDoubleCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TDoubleCharValueHashIterator(TDoubleCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TDoubleCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TDoubleCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TDoubleCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TDoubleCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TDoubleCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TDoubleCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleCharKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleCharHashIterator extends THashPrimitiveIterator implements TDoubleCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleCharHashMap we will be iterating over. + */ + TDoubleCharHashIterator(TDoubleCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleCharMap)) { + return false; + } + TDoubleCharMap that = (TDoubleCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + char val = in.readChar(); + put(key, val); + } + } +} // TDoubleCharHashMap diff --git a/src/gnu/trove/map/hash/TDoubleDoubleHashMap.java b/src/gnu/trove/map/hash/TDoubleDoubleHashMap.java new file mode 100644 index 0000000..1290b50 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleDoubleHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleDoubleHashMap extends TDoubleDoubleHash implements TDoubleDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TDoubleDoubleHashMap instance with the default + * capacity and load factor. + */ + public TDoubleDoubleHashMap() { + super(); + } + + /** + * Creates a new TDoubleDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TDoubleDoubleHashMap(int initialCapacity, float loadFactor, double noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleDoubleHashMap instance containing all of + * the entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a double array containing the values. + */ + public TDoubleDoubleHashMap(double[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleDoubleHashMap instance containing all of + * the entries in the map passed in. + * + * @param map + * a TDoubleDoubleMap that will be duplicated. + */ + public TDoubleDoubleHashMap(TDoubleDoubleMap map) { + super(map.size()); + if (map instanceof TDoubleDoubleHashMap) { + TDoubleDoubleHashMap hashmap = (TDoubleDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(double key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(double key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(double key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleDoubleMap map) { + ensureCapacity(map.size()); + TDoubleDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(double key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleDoubleIterator iterator() { + return new TDoubleDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleDoubleProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(double key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleDoubleKeyHashIterator(TDoubleDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleDoubleValueHashIterator(TDoubleDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleDoubleKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleDoubleHashIterator extends THashPrimitiveIterator implements TDoubleDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleDoubleHashMap we will be iterating over. + */ + TDoubleDoubleHashIterator(TDoubleDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleDoubleMap)) { + return false; + } + TDoubleDoubleMap that = (TDoubleDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + double val = in.readDouble(); + put(key, val); + } + } +} // TDoubleDoubleHashMap diff --git a/src/gnu/trove/map/hash/TDoubleFloatHashMap.java b/src/gnu/trove/map/hash/TDoubleFloatHashMap.java new file mode 100644 index 0000000..53f22c5 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleFloatHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleFloatHashMap extends TDoubleFloatHash implements TDoubleFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TDoubleFloatHashMap instance with the default + * capacity and load factor. + */ + public TDoubleFloatHashMap() { + super(); + } + + /** + * Creates a new TDoubleFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TDoubleFloatHashMap(int initialCapacity, float loadFactor, double noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a float array containing the values. + */ + public TDoubleFloatHashMap(double[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleFloatMap that will be duplicated. + */ + public TDoubleFloatHashMap(TDoubleFloatMap map) { + super(map.size()); + if (map instanceof TDoubleFloatHashMap) { + TDoubleFloatHashMap hashmap = (TDoubleFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(double key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(double key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(double key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleFloatMap map) { + ensureCapacity(map.size()); + TDoubleFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(double key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleFloatIterator iterator() { + return new TDoubleFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleFloatProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(double key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleFloatKeyHashIterator(TDoubleFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TDoubleFloatValueHashIterator(TDoubleFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TDoubleFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TDoubleFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TDoubleFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TDoubleFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TDoubleFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TDoubleFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleFloatKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleFloatHashIterator extends THashPrimitiveIterator implements TDoubleFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleFloatHashMap we will be iterating over. + */ + TDoubleFloatHashIterator(TDoubleFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleFloatMap)) { + return false; + } + TDoubleFloatMap that = (TDoubleFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + float val = in.readFloat(); + put(key, val); + } + } +} // TDoubleFloatHashMap diff --git a/src/gnu/trove/map/hash/TDoubleIntHashMap.java b/src/gnu/trove/map/hash/TDoubleIntHashMap.java new file mode 100644 index 0000000..2d1d727 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleIntHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleIntHashMap extends TDoubleIntHash implements TDoubleIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TDoubleIntHashMap instance with the default + * capacity and load factor. + */ + public TDoubleIntHashMap() { + super(); + } + + /** + * Creates a new TDoubleIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TDoubleIntHashMap(int initialCapacity, float loadFactor, double noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a int array containing the values. + */ + public TDoubleIntHashMap(double[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleIntMap that will be duplicated. + */ + public TDoubleIntHashMap(TDoubleIntMap map) { + super(map.size()); + if (map instanceof TDoubleIntHashMap) { + TDoubleIntHashMap hashmap = (TDoubleIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(double key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(double key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(double key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleIntMap map) { + ensureCapacity(map.size()); + TDoubleIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(double key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleIntIterator iterator() { + return new TDoubleIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleIntProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(double key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleIntKeyHashIterator(TDoubleIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TDoubleIntValueHashIterator(TDoubleIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TDoubleIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TDoubleIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TDoubleIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TDoubleIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TDoubleIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TDoubleIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleIntKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleIntHashIterator extends THashPrimitiveIterator implements TDoubleIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleIntHashMap we will be iterating over. + */ + TDoubleIntHashIterator(TDoubleIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleIntMap)) { + return false; + } + TDoubleIntMap that = (TDoubleIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + int val = in.readInt(); + put(key, val); + } + } +} // TDoubleIntHashMap diff --git a/src/gnu/trove/map/hash/TDoubleLongHashMap.java b/src/gnu/trove/map/hash/TDoubleLongHashMap.java new file mode 100644 index 0000000..419853a --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleLongHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleLongHashMap extends TDoubleLongHash implements TDoubleLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TDoubleLongHashMap instance with the default + * capacity and load factor. + */ + public TDoubleLongHashMap() { + super(); + } + + /** + * Creates a new TDoubleLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TDoubleLongHashMap(int initialCapacity, float loadFactor, double noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a long array containing the values. + */ + public TDoubleLongHashMap(double[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleLongMap that will be duplicated. + */ + public TDoubleLongHashMap(TDoubleLongMap map) { + super(map.size()); + if (map instanceof TDoubleLongHashMap) { + TDoubleLongHashMap hashmap = (TDoubleLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(double key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(double key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(double key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleLongMap map) { + ensureCapacity(map.size()); + TDoubleLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(double key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleLongIterator iterator() { + return new TDoubleLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleLongProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(double key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleLongKeyHashIterator(TDoubleLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TDoubleLongValueHashIterator(TDoubleLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TDoubleLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TDoubleLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TDoubleLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TDoubleLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TDoubleLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TDoubleLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleLongKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleLongHashIterator extends THashPrimitiveIterator implements TDoubleLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleLongHashMap we will be iterating over. + */ + TDoubleLongHashIterator(TDoubleLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleLongMap)) { + return false; + } + TDoubleLongMap that = (TDoubleLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + long val = in.readLong(); + put(key, val); + } + } +} // TDoubleLongHashMap diff --git a/src/gnu/trove/map/hash/TDoubleObjectHashMap.java b/src/gnu/trove/map/hash/TDoubleObjectHashMap.java new file mode 100644 index 0000000..18ad697 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TDoubleObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TDoubleObjectProcedure; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.iterator.TDoubleObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TDoubleSet; +import gnu.trove.TDoubleCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for double keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TDoubleObjectHashMap extends TDoubleHash implements TDoubleObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TDoubleObjectProcedure PUT_ALL_PROC = new TDoubleObjectProcedure() { + @Override + public boolean execute(double key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected double no_entry_key; + + /** + * Creates a new TDoubleObjectHashMap instance with the default + * capacity and load factor. + */ + public TDoubleObjectHashMap() { + super(); + } + + /** + * Creates a new TDoubleObjectHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TDoubleObjectHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TDoubleObjectHashMap instance with a prime value + * at or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TDoubleObjectHashMap(int initialCapacity, float loadFactor, double noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TDoubleObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TDoubleObjectMap to be copied. + */ + public TDoubleObjectHashMap(TDoubleObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public double getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(double key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(double key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(double key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(double key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public double[] keys() { + double[] keys = new double[size()]; + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public double[] keys(double[] dest) { + if (dest.length < _size) { + dest = new double[_size]; + } + + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TDoubleObjectIterator iterator() { + return new TDoubleObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TDoubleObjectProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TDoubleObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleObjectMap)) { + return false; + } + TDoubleObjectMap that = (TDoubleObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TDoubleObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + double key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleHashIterator(TDoubleObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return null != TDoubleObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TDoubleObjectHashMap.this.containsKey(((Double) element).doubleValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + if (collection == this) { + return true; + } + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TDoubleHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** the collection on which the iterator operates */ + private final TDoubleHash _hash; + + /** {@inheritDoc} */ + public TDoubleHashIterator(TDoubleHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TDoubleObjectValueHashIterator(TDoubleObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TDoubleObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TDoubleObjectHashMap _map; + + public TDoubleObjectValueHashIterator(TDoubleObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TDoubleObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TDoubleObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TDoubleObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TDoubleObjectHashIterator extends THashPrimitiveIterator implements TDoubleObjectIterator { + + /** the collection being iterated over */ + private final TDoubleObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TDoubleObjectHashIterator(TDoubleObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TDoubleObjectHashMap diff --git a/src/gnu/trove/map/hash/TDoubleShortHashMap.java b/src/gnu/trove/map/hash/TDoubleShortHashMap.java new file mode 100644 index 0000000..3cfeea9 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleShortHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleShortHashMap extends TDoubleShortHash implements TDoubleShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TDoubleShortHashMap instance with the default + * capacity and load factor. + */ + public TDoubleShortHashMap() { + super(); + } + + /** + * Creates a new TDoubleShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TDoubleShortHashMap(int initialCapacity, float loadFactor, double noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a short array containing the values. + */ + public TDoubleShortHashMap(double[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleShortMap that will be duplicated. + */ + public TDoubleShortHashMap(TDoubleShortMap map) { + super(map.size()); + if (map instanceof TDoubleShortHashMap) { + TDoubleShortHashMap hashmap = (TDoubleShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(double key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(double key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(double key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleShortMap map) { + ensureCapacity(map.size()); + TDoubleShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(double key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleShortIterator iterator() { + return new TDoubleShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleShortProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(double key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleShortKeyHashIterator(TDoubleShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TDoubleShortValueHashIterator(TDoubleShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TDoubleShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TDoubleShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TDoubleShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TDoubleShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TDoubleShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TDoubleShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleShortKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleShortHashIterator extends THashPrimitiveIterator implements TDoubleShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleShortHashMap we will be iterating over. + */ + TDoubleShortHashIterator(TDoubleShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleShortMap)) { + return false; + } + TDoubleShortMap that = (TDoubleShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + short val = in.readShort(); + put(key, val); + } + } +} // TDoubleShortHashMap diff --git a/src/gnu/trove/map/hash/TFloatByteHashMap.java b/src/gnu/trove/map/hash/TFloatByteHashMap.java new file mode 100644 index 0000000..82bff6a --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatByteHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatByteHashMap extends TFloatByteHash implements TFloatByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TFloatByteHashMap instance with the default + * capacity and load factor. + */ + public TFloatByteHashMap() { + super(); + } + + /** + * Creates a new TFloatByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TFloatByteHashMap(int initialCapacity, float loadFactor, float noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a byte array containing the values. + */ + public TFloatByteHashMap(float[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatByteMap that will be duplicated. + */ + public TFloatByteHashMap(TFloatByteMap map) { + super(map.size()); + if (map instanceof TFloatByteHashMap) { + TFloatByteHashMap hashmap = (TFloatByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(float key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(float key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(float key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatByteMap map) { + ensureCapacity(map.size()); + TFloatByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(float key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatByteIterator iterator() { + return new TFloatByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatByteProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatByteKeyHashIterator(TFloatByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TFloatByteValueHashIterator(TFloatByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TFloatByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TFloatByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TFloatByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TFloatByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TFloatByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TFloatByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatByteKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatByteHashIterator extends THashPrimitiveIterator implements TFloatByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatByteHashMap we will be iterating over. + */ + TFloatByteHashIterator(TFloatByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatByteMap)) { + return false; + } + TFloatByteMap that = (TFloatByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + byte val = in.readByte(); + put(key, val); + } + } +} // TFloatByteHashMap diff --git a/src/gnu/trove/map/hash/TFloatCharHashMap.java b/src/gnu/trove/map/hash/TFloatCharHashMap.java new file mode 100644 index 0000000..e8ddba2 --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatCharHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatCharHashMap extends TFloatCharHash implements TFloatCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TFloatCharHashMap instance with the default + * capacity and load factor. + */ + public TFloatCharHashMap() { + super(); + } + + /** + * Creates a new TFloatCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TFloatCharHashMap(int initialCapacity, float loadFactor, float noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a char array containing the values. + */ + public TFloatCharHashMap(float[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatCharMap that will be duplicated. + */ + public TFloatCharHashMap(TFloatCharMap map) { + super(map.size()); + if (map instanceof TFloatCharHashMap) { + TFloatCharHashMap hashmap = (TFloatCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(float key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(float key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(float key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatCharMap map) { + ensureCapacity(map.size()); + TFloatCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(float key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatCharIterator iterator() { + return new TFloatCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatCharProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(float key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatCharKeyHashIterator(TFloatCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TFloatCharValueHashIterator(TFloatCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TFloatCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TFloatCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TFloatCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TFloatCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TFloatCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TFloatCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatCharKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatCharHashIterator extends THashPrimitiveIterator implements TFloatCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatCharHashMap we will be iterating over. + */ + TFloatCharHashIterator(TFloatCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatCharMap)) { + return false; + } + TFloatCharMap that = (TFloatCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + char val = in.readChar(); + put(key, val); + } + } +} // TFloatCharHashMap diff --git a/src/gnu/trove/map/hash/TFloatDoubleHashMap.java b/src/gnu/trove/map/hash/TFloatDoubleHashMap.java new file mode 100644 index 0000000..625007d --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatDoubleHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatDoubleHashMap extends TFloatDoubleHash implements TFloatDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TFloatDoubleHashMap instance with the default + * capacity and load factor. + */ + public TFloatDoubleHashMap() { + super(); + } + + /** + * Creates a new TFloatDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TFloatDoubleHashMap(int initialCapacity, float loadFactor, float noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a double array containing the values. + */ + public TFloatDoubleHashMap(float[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatDoubleMap that will be duplicated. + */ + public TFloatDoubleHashMap(TFloatDoubleMap map) { + super(map.size()); + if (map instanceof TFloatDoubleHashMap) { + TFloatDoubleHashMap hashmap = (TFloatDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(float key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(float key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(float key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatDoubleMap map) { + ensureCapacity(map.size()); + TFloatDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(float key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatDoubleIterator iterator() { + return new TFloatDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatDoubleProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(float key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatDoubleKeyHashIterator(TFloatDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TFloatDoubleValueHashIterator(TFloatDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TFloatDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TFloatDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TFloatDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TFloatDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TFloatDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TFloatDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatDoubleKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatDoubleHashIterator extends THashPrimitiveIterator implements TFloatDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatDoubleHashMap we will be iterating over. + */ + TFloatDoubleHashIterator(TFloatDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatDoubleMap)) { + return false; + } + TFloatDoubleMap that = (TFloatDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + double val = in.readDouble(); + put(key, val); + } + } +} // TFloatDoubleHashMap diff --git a/src/gnu/trove/map/hash/TFloatFloatHashMap.java b/src/gnu/trove/map/hash/TFloatFloatHashMap.java new file mode 100644 index 0000000..68a68ae --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatFloatHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatFloatHashMap extends TFloatFloatHash implements TFloatFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TFloatFloatHashMap instance with the default + * capacity and load factor. + */ + public TFloatFloatHashMap() { + super(); + } + + /** + * Creates a new TFloatFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TFloatFloatHashMap(int initialCapacity, float loadFactor, float noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a float array containing the values. + */ + public TFloatFloatHashMap(float[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatFloatMap that will be duplicated. + */ + public TFloatFloatHashMap(TFloatFloatMap map) { + super(map.size()); + if (map instanceof TFloatFloatHashMap) { + TFloatFloatHashMap hashmap = (TFloatFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(float key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(float key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(float key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatFloatMap map) { + ensureCapacity(map.size()); + TFloatFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(float key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatFloatIterator iterator() { + return new TFloatFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatFloatProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(float key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatFloatKeyHashIterator(TFloatFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatFloatValueHashIterator(TFloatFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatFloatKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatFloatHashIterator extends THashPrimitiveIterator implements TFloatFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatFloatHashMap we will be iterating over. + */ + TFloatFloatHashIterator(TFloatFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatFloatMap)) { + return false; + } + TFloatFloatMap that = (TFloatFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + float val = in.readFloat(); + put(key, val); + } + } +} // TFloatFloatHashMap diff --git a/src/gnu/trove/map/hash/TFloatIntHashMap.java b/src/gnu/trove/map/hash/TFloatIntHashMap.java new file mode 100644 index 0000000..a0b81f7 --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatIntHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatIntHashMap extends TFloatIntHash implements TFloatIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TFloatIntHashMap instance with the default + * capacity and load factor. + */ + public TFloatIntHashMap() { + super(); + } + + /** + * Creates a new TFloatIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TFloatIntHashMap(int initialCapacity, float loadFactor, float noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a int array containing the values. + */ + public TFloatIntHashMap(float[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatIntMap that will be duplicated. + */ + public TFloatIntHashMap(TFloatIntMap map) { + super(map.size()); + if (map instanceof TFloatIntHashMap) { + TFloatIntHashMap hashmap = (TFloatIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(float key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(float key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(float key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatIntMap map) { + ensureCapacity(map.size()); + TFloatIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(float key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatIntIterator iterator() { + return new TFloatIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatIntProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(float key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatIntKeyHashIterator(TFloatIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TFloatIntValueHashIterator(TFloatIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TFloatIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TFloatIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TFloatIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TFloatIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TFloatIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TFloatIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatIntKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatIntHashIterator extends THashPrimitiveIterator implements TFloatIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatIntHashMap we will be iterating over. + */ + TFloatIntHashIterator(TFloatIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatIntMap)) { + return false; + } + TFloatIntMap that = (TFloatIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + int val = in.readInt(); + put(key, val); + } + } +} // TFloatIntHashMap diff --git a/src/gnu/trove/map/hash/TFloatLongHashMap.java b/src/gnu/trove/map/hash/TFloatLongHashMap.java new file mode 100644 index 0000000..fa4a77e --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatLongHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatLongHashMap extends TFloatLongHash implements TFloatLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TFloatLongHashMap instance with the default + * capacity and load factor. + */ + public TFloatLongHashMap() { + super(); + } + + /** + * Creates a new TFloatLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TFloatLongHashMap(int initialCapacity, float loadFactor, float noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a long array containing the values. + */ + public TFloatLongHashMap(float[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatLongMap that will be duplicated. + */ + public TFloatLongHashMap(TFloatLongMap map) { + super(map.size()); + if (map instanceof TFloatLongHashMap) { + TFloatLongHashMap hashmap = (TFloatLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(float key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(float key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(float key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatLongMap map) { + ensureCapacity(map.size()); + TFloatLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(float key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatLongIterator iterator() { + return new TFloatLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatLongProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(float key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatLongKeyHashIterator(TFloatLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TFloatLongValueHashIterator(TFloatLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TFloatLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TFloatLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TFloatLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TFloatLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TFloatLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TFloatLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatLongKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatLongHashIterator extends THashPrimitiveIterator implements TFloatLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatLongHashMap we will be iterating over. + */ + TFloatLongHashIterator(TFloatLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatLongMap)) { + return false; + } + TFloatLongMap that = (TFloatLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + long val = in.readLong(); + put(key, val); + } + } +} // TFloatLongHashMap diff --git a/src/gnu/trove/map/hash/TFloatObjectHashMap.java b/src/gnu/trove/map/hash/TFloatObjectHashMap.java new file mode 100644 index 0000000..0963fb5 --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TFloatObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TFloatObjectProcedure; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.iterator.TFloatObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TFloatSet; +import gnu.trove.TFloatCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for float keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TFloatObjectHashMap extends TFloatHash implements TFloatObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TFloatObjectProcedure PUT_ALL_PROC = new TFloatObjectProcedure() { + @Override + public boolean execute(float key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected float no_entry_key; + + /** + * Creates a new TFloatObjectHashMap instance with the default + * capacity and load factor. + */ + public TFloatObjectHashMap() { + super(); + } + + /** + * Creates a new TFloatObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TFloatObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TFloatObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TFloatObjectHashMap(int initialCapacity, float loadFactor, float noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TFloatObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TFloatObjectMap to be copied. + */ + public TFloatObjectHashMap(TFloatObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public float getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(float key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(float key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(float key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(float key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public float[] keys() { + float[] keys = new float[size()]; + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public float[] keys(float[] dest) { + if (dest.length < _size) { + dest = new float[_size]; + } + + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TFloatObjectIterator iterator() { + return new TFloatObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TFloatObjectProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TFloatObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatObjectMap)) { + return false; + } + TFloatObjectMap that = (TFloatObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TFloatObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + float key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatHashIterator(TFloatObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return null != TFloatObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TFloatObjectHashMap.this.containsKey(((Float) element).floatValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + if (collection == this) { + return true; + } + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TFloatHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** the collection on which the iterator operates */ + private final TFloatHash _hash; + + /** {@inheritDoc} */ + public TFloatHashIterator(TFloatHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TFloatObjectValueHashIterator(TFloatObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TFloatObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TFloatObjectHashMap _map; + + public TFloatObjectValueHashIterator(TFloatObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TFloatObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TFloatObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TFloatObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TFloatObjectHashIterator extends THashPrimitiveIterator implements TFloatObjectIterator { + + /** the collection being iterated over */ + private final TFloatObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TFloatObjectHashIterator(TFloatObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TFloatObjectHashMap diff --git a/src/gnu/trove/map/hash/TFloatShortHashMap.java b/src/gnu/trove/map/hash/TFloatShortHashMap.java new file mode 100644 index 0000000..f1e6dce --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatShortHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatShortHashMap extends TFloatShortHash implements TFloatShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TFloatShortHashMap instance with the default + * capacity and load factor. + */ + public TFloatShortHashMap() { + super(); + } + + /** + * Creates a new TFloatShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TFloatShortHashMap(int initialCapacity, float loadFactor, float noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a short array containing the values. + */ + public TFloatShortHashMap(float[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatShortMap that will be duplicated. + */ + public TFloatShortHashMap(TFloatShortMap map) { + super(map.size()); + if (map instanceof TFloatShortHashMap) { + TFloatShortHashMap hashmap = (TFloatShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(float key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(float key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(float key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatShortMap map) { + ensureCapacity(map.size()); + TFloatShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(float key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatShortIterator iterator() { + return new TFloatShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatShortProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(float key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatShortKeyHashIterator(TFloatShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TFloatShortValueHashIterator(TFloatShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TFloatShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TFloatShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TFloatShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TFloatShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TFloatShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TFloatShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatShortKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatShortHashIterator extends THashPrimitiveIterator implements TFloatShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatShortHashMap we will be iterating over. + */ + TFloatShortHashIterator(TFloatShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatShortMap)) { + return false; + } + TFloatShortMap that = (TFloatShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + short val = in.readShort(); + put(key, val); + } + } +} // TFloatShortHashMap diff --git a/src/gnu/trove/map/hash/THashMap.java b/src/gnu/trove/map/hash/THashMap.java new file mode 100644 index 0000000..483d5d1 --- /dev/null +++ b/src/gnu/trove/map/hash/THashMap.java @@ -0,0 +1,914 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.function.TObjectFunction; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TMap; +import gnu.trove.procedure.TObjectObjectProcedure; +import gnu.trove.procedure.TObjectProcedure; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +/** + * An implementation of the Map interface which uses an open addressed hash + * table to store its contents. + *

+ * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: THashMap.java,v 1.1.2.8 2010/03/02 04:09:50 robeden Exp $ + */ + +public class THashMap extends TObjectHash implements TMap, Externalizable { + + static final long serialVersionUID = 1L; + + /** + * the values of the map + */ + protected transient V[] _values; + + /** + * Creates a new THashMap instance with the default capacity and + * load factor. + */ + public THashMap() { + super(); + } + + /** + * Creates a new THashMap instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public THashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new THashMap instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public THashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new THashMap instance which contains the key/value + * pairs in map. + * + * @param map + * a Map value + */ + public THashMap(Map map) { + this(map.size()); + putAll(map); + } + + /** + * Creates a new THashMap instance which contains the key/value + * pairs in map. + * + * @param map + * a Map value + */ + public THashMap(THashMap map) { + this(map.size()); + putAll(map); + } + + /** + * initialize the value array of the map. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + // noinspection unchecked + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V put(K key, V value) { + // insertKey() inserts the key if a slot if found and returns the index + int index = insertKey(key); + return doPut(value, index); + } + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V putIfAbsent(K key, V value) { + // insertKey() inserts the key if a slot if found and returns the index + int index = insertKey(key); + if (index < 0) { + return _values[-index - 1]; + } + return doPut(value, index); + } + + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + @SuppressWarnings({ "unchecked", "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Map)) { + return false; + } + Map that = (Map) other; + if (that.size() != this.size()) { + return false; + } + return forEachEntry(new EqProcedure(that)); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, V value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + private final class HashProcedure implements TObjectObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(K key, V value) { + h += HashFunctions.hash(key) ^ (value == null ? 0 : value.hashCode()); + return true; + } + } + + private final class EqProcedure implements TObjectObjectProcedure { + private final Map _otherMap; + + EqProcedure(Map otherMap) { + _otherMap = otherMap; + } + + @Override + public final boolean execute(K key, V value) { + // Check to make sure the key is there. This avoids problems that come up with + // null values. Since it is only caused in that cause, only do this when the + // value is null (to avoid extra work). + if (value == null && !_otherMap.containsKey(key)) { + return false; + } + + V oValue = _otherMap.get(key); + return oValue == value || (oValue != null && THashMap.this.equals(oValue, value)); + } + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TObjectObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectObjectProcedure procedure) { + Object[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TObjectObjectProcedure procedure) { + boolean modified = false; + Object[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + @Override + public void transformValues(TObjectFunction function) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + int oldSize = size(); + Object oldKeys[] = _set; + V oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = (V[]) new Object[newCapacity]; + + // Process entries from the old array, skipping free and removed slots. Put the + // values into the appropriate place in the new array. + int count = 0; + for (int i = oldCapacity; i-- > 0;) { + Object o = oldKeys[i]; + + if (o == FREE || o == REMOVED) + continue; + + int index = insertKey((K) o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldKeys); + } + _values[index] = oldVals[i]; + // + count++; + } + + // Last check: size before and after should be the same + reportPotentialConcurrentMod(size(), oldSize); + } + + /** + * retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V get(Object key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + /** + * Empties the map. + */ + @Override + public void clear() { + if (size() == 0) { + return; // optimization + } + + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return an Object value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V remove(Object key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * removes the mapping at index from the map. + * + * @param index + * an int value + */ + @Override + public void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + /** + * Returns a view on the values of the map. + * + * @return a Collection value + */ + @Override + public Collection values() { + return new ValueView(); + } + + /** + * returns a Set view on the keys of the map. + * + * @return a Set value + */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new EntryView(); + } + + /** + * checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + Object[] set = _set; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && val == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && (val == vals[i] || equals(val, vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** + * checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + // noinspection unchecked + return contains(key); + } + + /** + * copies the key/value mappings in map into this map. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry e : map.entrySet()) { + put(e.getKey(), e.getValue()); + } + } + + /** + * a view onto the values of the map. + */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(THashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + Object[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && value == values[i] + || (null != values[i] && THashMap.this.equals(values[i], value))) { + + removeAt(i); + return true; + } + } + + return false; + } + } + + /** + * a view onto the entries of the map. + */ + protected class EntryView extends MapBackedView> { + + private final class EntryIterator extends TObjectHashIterator { + + EntryIterator(THashMap map) { + super(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Entry objectAtIndex(final int index) { + return new Entry((K) _set[index], _values[index], index); + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator> iterator() { + return new EntryIterator(THashMap.this); + } + + @Override + public boolean removeElement(Map.Entry entry) { + if (entry == null) + return false; + + // have to effectively reimplement Map.remove here + // because we need to return true/false depending on + // whether the removal took place. Since the Entry's + // value can be null, this means that we can't rely + // on the value of the object returned by Map.remove() + // to determine whether a deletion actually happened. + // + // Note also that the deletion is only legal if + // both the key and the value match. + V val; + int index; + + K key = keyForEntry(entry); + index = index(key); + if (index >= 0) { + val = valueForEntry(entry); + if (val == _values[index] || (null != val && THashMap.this.equals(val, _values[index]))) { + removeAt(index); // clear key,state; adjust size + return true; + } + } + return false; + } + + @Override + public boolean containsElement(Map.Entry entry) { + V val = get(keyForEntry(entry)); + V entryValue = entry.getValue(); + return entryValue == val || (null != val && THashMap.this.equals(val, entryValue)); + } + + protected V valueForEntry(Map.Entry entry) { + return entry.getValue(); + } + + protected K keyForEntry(Map.Entry entry) { + return entry.getKey(); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + try { + return removeElement((E) o); + } catch (ClassCastException ex) { + return false; + } + } + + // public boolean containsAll( Collection collection ) { + // for ( Object element : collection ) { + // if ( !contains( element ) ) { + // return false; + // } + // } + // return true; + // } + + @Override + public void clear() { + THashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return THashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return THashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + Iterator i = iterator(); + if (!i.hasNext()) + return "{}"; + + StringBuilder sb = new StringBuilder(); + sb.append('{'); + for (;;) { + E e = i.next(); + sb.append(e == this ? "(this Collection)" : e); + if (!i.hasNext()) + return sb.append('}').toString(); + sb.append(", "); + } + } + } + + /** + * a view onto the keys of the map. + */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(THashMap.this); + } + + @Override + public boolean removeElement(K key) { + return null != THashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return THashMap.this.contains(key); + } + } + + final class Entry implements Map.Entry { + + private K key; + private V val; + private final int index; + + Entry(final K key, V value, final int index) { + this.key = key; + this.val = value; + this.index = index; + } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public V setValue(V o) { + if (_values[index] != val) { + throw new ConcurrentModificationException(); + } + // need to return previous value + V retval = val; + // update this entry's value, in case setValue is called again + _values[index] = o; + val = o; + return retval; + } + + @Override + public boolean equals(Object o) { + if (o instanceof Map.Entry) { + Map.Entry e1 = this; + Map.Entry e2 = (Map.Entry) o; + return (THashMap.this.equals(e1.getKey(), e2.getKey())) + && (THashMap.this.equals(e1.getValue(), e1.getValue())); + } + return false; + } + + @Override + public int hashCode() { + return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); + } + + @Override + public String toString() { + return key + "=" + val; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + // noinspection unchecked + V val = (V) in.readObject(); + put(key, val); + } + } +} // THashMap diff --git a/src/gnu/trove/map/hash/TIntByteHashMap.java b/src/gnu/trove/map/hash/TIntByteHashMap.java new file mode 100644 index 0000000..6b8b159 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntByteHashMap extends TIntByteHash implements TIntByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TIntByteHashMap instance with the default capacity + * and load factor. + */ + public TIntByteHashMap() { + super(); + } + + /** + * Creates a new TIntByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TIntByteHashMap(int initialCapacity, float loadFactor, int noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TIntByteHashMap(int[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntByteMap that will be duplicated. + */ + public TIntByteHashMap(TIntByteMap map) { + super(map.size()); + if (map instanceof TIntByteHashMap) { + TIntByteHashMap hashmap = (TIntByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(int key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(int key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(int key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntByteMap map) { + ensureCapacity(map.size()); + TIntByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(int key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntByteIterator iterator() { + return new TIntByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntByteProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntByteKeyHashIterator(TIntByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TIntByteValueHashIterator(TIntByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TIntByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TIntByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TIntByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TIntByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TIntByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TIntByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntByteKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntByteHashIterator extends THashPrimitiveIterator implements TIntByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntByteHashMap we will be iterating over. + */ + TIntByteHashIterator(TIntByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntByteMap)) { + return false; + } + TIntByteMap that = (TIntByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + byte val = in.readByte(); + put(key, val); + } + } +} // TIntByteHashMap diff --git a/src/gnu/trove/map/hash/TIntCharHashMap.java b/src/gnu/trove/map/hash/TIntCharHashMap.java new file mode 100644 index 0000000..13aba88 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntCharHashMap extends TIntCharHash implements TIntCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TIntCharHashMap instance with the default capacity + * and load factor. + */ + public TIntCharHashMap() { + super(); + } + + /** + * Creates a new TIntCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TIntCharHashMap(int initialCapacity, float loadFactor, int noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TIntCharHashMap(int[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntCharMap that will be duplicated. + */ + public TIntCharHashMap(TIntCharMap map) { + super(map.size()); + if (map instanceof TIntCharHashMap) { + TIntCharHashMap hashmap = (TIntCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(int key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(int key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(int key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntCharMap map) { + ensureCapacity(map.size()); + TIntCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(int key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntCharIterator iterator() { + return new TIntCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntCharProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(int key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntCharKeyHashIterator(TIntCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TIntCharValueHashIterator(TIntCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TIntCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TIntCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TIntCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TIntCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TIntCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TIntCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntCharKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntCharHashIterator extends THashPrimitiveIterator implements TIntCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntCharHashMap we will be iterating over. + */ + TIntCharHashIterator(TIntCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntCharMap)) { + return false; + } + TIntCharMap that = (TIntCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + char val = in.readChar(); + put(key, val); + } + } +} // TIntCharHashMap diff --git a/src/gnu/trove/map/hash/TIntDoubleHashMap.java b/src/gnu/trove/map/hash/TIntDoubleHashMap.java new file mode 100644 index 0000000..8914c53 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntDoubleHashMap extends TIntDoubleHash implements TIntDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TIntDoubleHashMap instance with the default + * capacity and load factor. + */ + public TIntDoubleHashMap() { + super(); + } + + /** + * Creates a new TIntDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TIntDoubleHashMap(int initialCapacity, float loadFactor, int noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TIntDoubleHashMap(int[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntDoubleMap that will be duplicated. + */ + public TIntDoubleHashMap(TIntDoubleMap map) { + super(map.size()); + if (map instanceof TIntDoubleHashMap) { + TIntDoubleHashMap hashmap = (TIntDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(int key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(int key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(int key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntDoubleMap map) { + ensureCapacity(map.size()); + TIntDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(int key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntDoubleIterator iterator() { + return new TIntDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntDoubleProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(int key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntDoubleKeyHashIterator(TIntDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TIntDoubleValueHashIterator(TIntDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TIntDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TIntDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TIntDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TIntDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TIntDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TIntDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntDoubleKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntDoubleHashIterator extends THashPrimitiveIterator implements TIntDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntDoubleHashMap we will be iterating over. + */ + TIntDoubleHashIterator(TIntDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntDoubleMap)) { + return false; + } + TIntDoubleMap that = (TIntDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + double val = in.readDouble(); + put(key, val); + } + } +} // TIntDoubleHashMap diff --git a/src/gnu/trove/map/hash/TIntFloatHashMap.java b/src/gnu/trove/map/hash/TIntFloatHashMap.java new file mode 100644 index 0000000..7b5c088 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntFloatHashMap extends TIntFloatHash implements TIntFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TIntFloatHashMap instance with the default + * capacity and load factor. + */ + public TIntFloatHashMap() { + super(); + } + + /** + * Creates a new TIntFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TIntFloatHashMap(int initialCapacity, float loadFactor, int noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TIntFloatHashMap(int[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntFloatMap that will be duplicated. + */ + public TIntFloatHashMap(TIntFloatMap map) { + super(map.size()); + if (map instanceof TIntFloatHashMap) { + TIntFloatHashMap hashmap = (TIntFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(int key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(int key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(int key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntFloatMap map) { + ensureCapacity(map.size()); + TIntFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(int key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntFloatIterator iterator() { + return new TIntFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntFloatProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(int key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntFloatKeyHashIterator(TIntFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TIntFloatValueHashIterator(TIntFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TIntFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TIntFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TIntFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TIntFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TIntFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TIntFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntFloatKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntFloatHashIterator extends THashPrimitiveIterator implements TIntFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntFloatHashMap we will be iterating over. + */ + TIntFloatHashIterator(TIntFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntFloatMap)) { + return false; + } + TIntFloatMap that = (TIntFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + float val = in.readFloat(); + put(key, val); + } + } +} // TIntFloatHashMap diff --git a/src/gnu/trove/map/hash/TIntIntHashMap.java b/src/gnu/trove/map/hash/TIntIntHashMap.java new file mode 100644 index 0000000..fdb68d5 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntIntHashMap extends TIntIntHash implements TIntIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TIntIntHashMap instance with the default capacity + * and load factor. + */ + public TIntIntHashMap() { + super(); + } + + /** + * Creates a new TIntIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TIntIntHashMap(int initialCapacity, float loadFactor, int noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TIntIntHashMap(int[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntIntMap that will be duplicated. + */ + public TIntIntHashMap(TIntIntMap map) { + super(map.size()); + if (map instanceof TIntIntHashMap) { + TIntIntHashMap hashmap = (TIntIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(int key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(int key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(int key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntIntMap map) { + ensureCapacity(map.size()); + TIntIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(int key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntIntIterator iterator() { + return new TIntIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntIntProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(int key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntIntKeyHashIterator(TIntIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntIntValueHashIterator(TIntIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntIntKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntIntHashIterator extends THashPrimitiveIterator implements TIntIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntIntHashMap we will be iterating over. + */ + TIntIntHashIterator(TIntIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntIntMap)) { + return false; + } + TIntIntMap that = (TIntIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + int val = in.readInt(); + put(key, val); + } + } +} // TIntIntHashMap diff --git a/src/gnu/trove/map/hash/TIntLongHashMap.java b/src/gnu/trove/map/hash/TIntLongHashMap.java new file mode 100644 index 0000000..918cc65 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntLongHashMap extends TIntLongHash implements TIntLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TIntLongHashMap instance with the default capacity + * and load factor. + */ + public TIntLongHashMap() { + super(); + } + + /** + * Creates a new TIntLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TIntLongHashMap(int initialCapacity, float loadFactor, int noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TIntLongHashMap(int[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntLongMap that will be duplicated. + */ + public TIntLongHashMap(TIntLongMap map) { + super(map.size()); + if (map instanceof TIntLongHashMap) { + TIntLongHashMap hashmap = (TIntLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(int key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(int key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(int key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntLongMap map) { + ensureCapacity(map.size()); + TIntLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(int key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntLongIterator iterator() { + return new TIntLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntLongProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(int key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntLongKeyHashIterator(TIntLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TIntLongValueHashIterator(TIntLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TIntLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TIntLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TIntLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TIntLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TIntLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TIntLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntLongKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntLongHashIterator extends THashPrimitiveIterator implements TIntLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntLongHashMap we will be iterating over. + */ + TIntLongHashIterator(TIntLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntLongMap)) { + return false; + } + TIntLongMap that = (TIntLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + long val = in.readLong(); + put(key, val); + } + } +} // TIntLongHashMap diff --git a/src/gnu/trove/map/hash/TIntObjectHashMap.java b/src/gnu/trove/map/hash/TIntObjectHashMap.java new file mode 100644 index 0000000..91c0456 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntObjectHashMap.java @@ -0,0 +1,1000 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TIntObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TIntObjectProcedure; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.TIntObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TIntSet; +import gnu.trove.TIntCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for int keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TIntObjectHashMap extends TIntHash implements TIntObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TIntObjectProcedure PUT_ALL_PROC = new TIntObjectProcedure() { + @Override + public boolean execute(int key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected int no_entry_key; + + /** + * Creates a new TIntObjectHashMap instance with the default + * capacity and load factor. + */ + public TIntObjectHashMap() { + super(); + } + + /** + * Creates a new TIntObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TIntObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TIntObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TIntObjectHashMap(int initialCapacity, float loadFactor, int noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TIntObjectHashMap that contains the entries in the + * map passed to it. + * + * @param map + * the TIntObjectMap to be copied. + */ + public TIntObjectHashMap(TIntObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + @Override + public int getNoEntryKey() { + return no_entry_key; + } + + @Override + public boolean containsKey(int key) { + return contains(key); + } + + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + @Override + public V get(int key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + @Override + public V put(int key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + @Override + public V putIfAbsent(int key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + @Override + public V remove(int key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + @Override + public void putAll(TIntObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + @Override + public TIntSet keySet() { + return new KeyView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public int[] keys() { + int[] keys = new int[size()]; + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public int[] keys(int[] dest) { + if (dest.length < _size) { + dest = new int[_size]; + } + + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + @Override + public Collection valueCollection() { + return new ValueView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + @Override + public TIntObjectIterator iterator() { + return new TIntObjectHashIterator(this); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TIntObjectProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TIntObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntObjectMap)) { + return false; + } + TIntObjectMap that = (TIntObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TIntObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + int key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TIntSet { + + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + @Override + public int size() { + return _size; + } + + @Override + public boolean isEmpty() { + return _size == 0; + } + + @Override + public boolean contains(int entry) { + return TIntObjectHashMap.this.containsKey(entry); + } + + @Override + public TIntIterator iterator() { + return new TIntHashIterator(TIntObjectHashMap.this); + } + + @Override + public int[] toArray() { + return keys(); + } + + @Override + public int[] toArray(int[] dest) { + return keys(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(int entry) { + return null != TIntObjectHashMap.this.remove(entry); + } + + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TIntObjectHashMap.this.containsKey(((Integer) element).intValue())) { + + return false; + } + } + return true; + } + + @Override + public boolean containsAll(TIntCollection collection) { + if (collection == this) { + return true; + } + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + @Override + public boolean removeAll(TIntCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + @Override + public void clear() { + TIntObjectHashMap.this.clear(); + } + + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntObjectHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TIntHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** the collection on which the iterator operates */ + private final TIntHash _hash; + + public TIntHashIterator(TIntHash hash) { + super(hash); + this._hash = hash; + } + + @Override + public int next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TIntObjectValueHashIterator(TIntObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TIntObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TIntObjectHashMap _map; + + public TIntObjectValueHashIterator(TIntObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TIntObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TIntObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TIntObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TIntObjectHashIterator extends THashPrimitiveIterator implements TIntObjectIterator { + + /** the collection being iterated over */ + private final TIntObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TIntObjectHashIterator(TIntObjectHashMap map) { + super(map); + this._map = map; + } + + @Override + public void advance() { + moveToNextIndex(); + } + + @Override + public int key() { + return _map._set[_index]; + } + + @Override + public V value() { + return _map._values[_index]; + } + + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TIntObjectHashMap diff --git a/src/gnu/trove/map/hash/TIntShortHashMap.java b/src/gnu/trove/map/hash/TIntShortHashMap.java new file mode 100644 index 0000000..70e09b1 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntShortHashMap extends TIntShortHash implements TIntShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TIntShortHashMap instance with the default + * capacity and load factor. + */ + public TIntShortHashMap() { + super(); + } + + /** + * Creates a new TIntShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TIntShortHashMap(int initialCapacity, float loadFactor, int noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TIntShortHashMap(int[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntShortMap that will be duplicated. + */ + public TIntShortHashMap(TIntShortMap map) { + super(map.size()); + if (map instanceof TIntShortHashMap) { + TIntShortHashMap hashmap = (TIntShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(int key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(int key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(int key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntShortMap map) { + ensureCapacity(map.size()); + TIntShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(int key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntShortIterator iterator() { + return new TIntShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntShortProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(int key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntShortKeyHashIterator(TIntShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TIntShortValueHashIterator(TIntShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TIntShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TIntShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TIntShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TIntShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TIntShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TIntShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntShortKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntShortHashIterator extends THashPrimitiveIterator implements TIntShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntShortHashMap we will be iterating over. + */ + TIntShortHashIterator(TIntShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntShortMap)) { + return false; + } + TIntShortMap that = (TIntShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + short val = in.readShort(); + put(key, val); + } + } +} // TIntShortHashMap diff --git a/src/gnu/trove/map/hash/TLongByteHashMap.java b/src/gnu/trove/map/hash/TLongByteHashMap.java new file mode 100644 index 0000000..177ba00 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongByteHashMap extends TLongByteHash implements TLongByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TLongByteHashMap instance with the default + * capacity and load factor. + */ + public TLongByteHashMap() { + super(); + } + + /** + * Creates a new TLongByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TLongByteHashMap(int initialCapacity, float loadFactor, long noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TLongByteHashMap(long[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongByteMap that will be duplicated. + */ + public TLongByteHashMap(TLongByteMap map) { + super(map.size()); + if (map instanceof TLongByteHashMap) { + TLongByteHashMap hashmap = (TLongByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(long key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(long key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(long key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongByteMap map) { + ensureCapacity(map.size()); + TLongByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(long key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongByteIterator iterator() { + return new TLongByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongByteProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongByteKeyHashIterator(TLongByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TLongByteValueHashIterator(TLongByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TLongByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TLongByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TLongByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TLongByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TLongByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TLongByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongByteKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongByteHashIterator extends THashPrimitiveIterator implements TLongByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongByteHashMap we will be iterating over. + */ + TLongByteHashIterator(TLongByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongByteMap)) { + return false; + } + TLongByteMap that = (TLongByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + byte val = in.readByte(); + put(key, val); + } + } +} // TLongByteHashMap diff --git a/src/gnu/trove/map/hash/TLongCharHashMap.java b/src/gnu/trove/map/hash/TLongCharHashMap.java new file mode 100644 index 0000000..0a45bba --- /dev/null +++ b/src/gnu/trove/map/hash/TLongCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongCharHashMap extends TLongCharHash implements TLongCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TLongCharHashMap instance with the default + * capacity and load factor. + */ + public TLongCharHashMap() { + super(); + } + + /** + * Creates a new TLongCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TLongCharHashMap(int initialCapacity, float loadFactor, long noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TLongCharHashMap(long[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongCharMap that will be duplicated. + */ + public TLongCharHashMap(TLongCharMap map) { + super(map.size()); + if (map instanceof TLongCharHashMap) { + TLongCharHashMap hashmap = (TLongCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(long key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(long key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(long key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongCharMap map) { + ensureCapacity(map.size()); + TLongCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(long key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongCharIterator iterator() { + return new TLongCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongCharProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(long key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongCharKeyHashIterator(TLongCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TLongCharValueHashIterator(TLongCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TLongCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TLongCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TLongCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TLongCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TLongCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TLongCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongCharKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongCharHashIterator extends THashPrimitiveIterator implements TLongCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongCharHashMap we will be iterating over. + */ + TLongCharHashIterator(TLongCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongCharMap)) { + return false; + } + TLongCharMap that = (TLongCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + char val = in.readChar(); + put(key, val); + } + } +} // TLongCharHashMap diff --git a/src/gnu/trove/map/hash/TLongDoubleHashMap.java b/src/gnu/trove/map/hash/TLongDoubleHashMap.java new file mode 100644 index 0000000..fd67bd8 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongDoubleHashMap extends TLongDoubleHash implements TLongDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TLongDoubleHashMap instance with the default + * capacity and load factor. + */ + public TLongDoubleHashMap() { + super(); + } + + /** + * Creates a new TLongDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TLongDoubleHashMap(int initialCapacity, float loadFactor, long noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TLongDoubleHashMap(long[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongDoubleMap that will be duplicated. + */ + public TLongDoubleHashMap(TLongDoubleMap map) { + super(map.size()); + if (map instanceof TLongDoubleHashMap) { + TLongDoubleHashMap hashmap = (TLongDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(long key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(long key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(long key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongDoubleMap map) { + ensureCapacity(map.size()); + TLongDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(long key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongDoubleIterator iterator() { + return new TLongDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongDoubleProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(long key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongDoubleKeyHashIterator(TLongDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TLongDoubleValueHashIterator(TLongDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TLongDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TLongDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TLongDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TLongDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TLongDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TLongDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongDoubleKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongDoubleHashIterator extends THashPrimitiveIterator implements TLongDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongDoubleHashMap we will be iterating over. + */ + TLongDoubleHashIterator(TLongDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongDoubleMap)) { + return false; + } + TLongDoubleMap that = (TLongDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + double val = in.readDouble(); + put(key, val); + } + } +} // TLongDoubleHashMap diff --git a/src/gnu/trove/map/hash/TLongFloatHashMap.java b/src/gnu/trove/map/hash/TLongFloatHashMap.java new file mode 100644 index 0000000..e5c47d1 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongFloatHashMap extends TLongFloatHash implements TLongFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TLongFloatHashMap instance with the default + * capacity and load factor. + */ + public TLongFloatHashMap() { + super(); + } + + /** + * Creates a new TLongFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TLongFloatHashMap(int initialCapacity, float loadFactor, long noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TLongFloatHashMap(long[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongFloatMap that will be duplicated. + */ + public TLongFloatHashMap(TLongFloatMap map) { + super(map.size()); + if (map instanceof TLongFloatHashMap) { + TLongFloatHashMap hashmap = (TLongFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(long key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(long key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(long key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongFloatMap map) { + ensureCapacity(map.size()); + TLongFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(long key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongFloatIterator iterator() { + return new TLongFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongFloatProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(long key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongFloatKeyHashIterator(TLongFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TLongFloatValueHashIterator(TLongFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TLongFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TLongFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TLongFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TLongFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TLongFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TLongFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongFloatKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongFloatHashIterator extends THashPrimitiveIterator implements TLongFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongFloatHashMap we will be iterating over. + */ + TLongFloatHashIterator(TLongFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongFloatMap)) { + return false; + } + TLongFloatMap that = (TLongFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + float val = in.readFloat(); + put(key, val); + } + } +} // TLongFloatHashMap diff --git a/src/gnu/trove/map/hash/TLongIntHashMap.java b/src/gnu/trove/map/hash/TLongIntHashMap.java new file mode 100644 index 0000000..48632ba --- /dev/null +++ b/src/gnu/trove/map/hash/TLongIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongIntHashMap extends TLongIntHash implements TLongIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TLongIntHashMap instance with the default capacity + * and load factor. + */ + public TLongIntHashMap() { + super(); + } + + /** + * Creates a new TLongIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TLongIntHashMap(int initialCapacity, float loadFactor, long noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TLongIntHashMap(long[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongIntMap that will be duplicated. + */ + public TLongIntHashMap(TLongIntMap map) { + super(map.size()); + if (map instanceof TLongIntHashMap) { + TLongIntHashMap hashmap = (TLongIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(long key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(long key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(long key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongIntMap map) { + ensureCapacity(map.size()); + TLongIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(long key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongIntIterator iterator() { + return new TLongIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongIntProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(long key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongIntKeyHashIterator(TLongIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TLongIntValueHashIterator(TLongIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TLongIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TLongIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TLongIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TLongIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TLongIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TLongIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongIntKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongIntHashIterator extends THashPrimitiveIterator implements TLongIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongIntHashMap we will be iterating over. + */ + TLongIntHashIterator(TLongIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongIntMap)) { + return false; + } + TLongIntMap that = (TLongIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + int val = in.readInt(); + put(key, val); + } + } +} // TLongIntHashMap diff --git a/src/gnu/trove/map/hash/TLongLongHashMap.java b/src/gnu/trove/map/hash/TLongLongHashMap.java new file mode 100644 index 0000000..915d53b --- /dev/null +++ b/src/gnu/trove/map/hash/TLongLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongLongHashMap extends TLongLongHash implements TLongLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TLongLongHashMap instance with the default + * capacity and load factor. + */ + public TLongLongHashMap() { + super(); + } + + /** + * Creates a new TLongLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TLongLongHashMap(int initialCapacity, float loadFactor, long noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TLongLongHashMap(long[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongLongMap that will be duplicated. + */ + public TLongLongHashMap(TLongLongMap map) { + super(map.size()); + if (map instanceof TLongLongHashMap) { + TLongLongHashMap hashmap = (TLongLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(long key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(long key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(long key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongLongMap map) { + ensureCapacity(map.size()); + TLongLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(long key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongLongIterator iterator() { + return new TLongLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongLongProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(long key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongLongKeyHashIterator(TLongLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongLongValueHashIterator(TLongLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongLongKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongLongHashIterator extends THashPrimitiveIterator implements TLongLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongLongHashMap we will be iterating over. + */ + TLongLongHashIterator(TLongLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongLongMap)) { + return false; + } + TLongLongMap that = (TLongLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + long val = in.readLong(); + put(key, val); + } + } +} // TLongLongHashMap diff --git a/src/gnu/trove/map/hash/TLongObjectHashMap.java b/src/gnu/trove/map/hash/TLongObjectHashMap.java new file mode 100644 index 0000000..9fe430c --- /dev/null +++ b/src/gnu/trove/map/hash/TLongObjectHashMap.java @@ -0,0 +1,1000 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TLongObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TLongObjectProcedure; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.iterator.TLongObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TLongSet; +import gnu.trove.TLongCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for long keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TLongObjectHashMap extends TLongHash implements TLongObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TLongObjectProcedure PUT_ALL_PROC = new TLongObjectProcedure() { + @Override + public boolean execute(long key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected long no_entry_key; + + /** + * Creates a new TLongObjectHashMap instance with the default + * capacity and load factor. + */ + public TLongObjectHashMap() { + super(); + } + + /** + * Creates a new TLongObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TLongObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TLongObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TLongObjectHashMap(int initialCapacity, float loadFactor, long noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TLongObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TLongObjectMap to be copied. + */ + public TLongObjectHashMap(TLongObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + @Override + public long getNoEntryKey() { + return no_entry_key; + } + + @Override + public boolean containsKey(long key) { + return contains(key); + } + + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + @Override + public V get(long key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + @Override + public V put(long key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + @Override + public V putIfAbsent(long key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + @Override + public V remove(long key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + @Override + public void putAll(TLongObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + @Override + public TLongSet keySet() { + return new KeyView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public long[] keys() { + long[] keys = new long[size()]; + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public long[] keys(long[] dest) { + if (dest.length < _size) { + dest = new long[_size]; + } + + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + @Override + public Collection valueCollection() { + return new ValueView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + @Override + public TLongObjectIterator iterator() { + return new TLongObjectHashIterator(this); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TLongObjectProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TLongObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongObjectMap)) { + return false; + } + TLongObjectMap that = (TLongObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TLongObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + long key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TLongSet { + + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + @Override + public int size() { + return _size; + } + + @Override + public boolean isEmpty() { + return _size == 0; + } + + @Override + public boolean contains(long entry) { + return TLongObjectHashMap.this.containsKey(entry); + } + + @Override + public TLongIterator iterator() { + return new TLongHashIterator(TLongObjectHashMap.this); + } + + @Override + public long[] toArray() { + return keys(); + } + + @Override + public long[] toArray(long[] dest) { + return keys(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(long entry) { + return null != TLongObjectHashMap.this.remove(entry); + } + + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TLongObjectHashMap.this.containsKey(((Long) element).longValue())) { + + return false; + } + } + return true; + } + + @Override + public boolean containsAll(TLongCollection collection) { + if (collection == this) { + return true; + } + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + @Override + public boolean removeAll(TLongCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + @Override + public void clear() { + TLongObjectHashMap.this.clear(); + } + + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongObjectHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TLongHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** the collection on which the iterator operates */ + private final TLongHash _hash; + + public TLongHashIterator(TLongHash hash) { + super(hash); + this._hash = hash; + } + + @Override + public long next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TLongObjectValueHashIterator(TLongObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TLongObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TLongObjectHashMap _map; + + public TLongObjectValueHashIterator(TLongObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TLongObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TLongObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TLongObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TLongObjectHashIterator extends THashPrimitiveIterator implements TLongObjectIterator { + + /** the collection being iterated over */ + private final TLongObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TLongObjectHashIterator(TLongObjectHashMap map) { + super(map); + this._map = map; + } + + @Override + public void advance() { + moveToNextIndex(); + } + + @Override + public long key() { + return _map._set[_index]; + } + + @Override + public V value() { + return _map._values[_index]; + } + + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TLongObjectHashMap diff --git a/src/gnu/trove/map/hash/TLongShortHashMap.java b/src/gnu/trove/map/hash/TLongShortHashMap.java new file mode 100644 index 0000000..07cfca3 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongShortHashMap extends TLongShortHash implements TLongShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TLongShortHashMap instance with the default + * capacity and load factor. + */ + public TLongShortHashMap() { + super(); + } + + /** + * Creates a new TLongShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TLongShortHashMap(int initialCapacity, float loadFactor, long noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TLongShortHashMap(long[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongShortMap that will be duplicated. + */ + public TLongShortHashMap(TLongShortMap map) { + super(map.size()); + if (map instanceof TLongShortHashMap) { + TLongShortHashMap hashmap = (TLongShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(long key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(long key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(long key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongShortMap map) { + ensureCapacity(map.size()); + TLongShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(long key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongShortIterator iterator() { + return new TLongShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongShortProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(long key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongShortKeyHashIterator(TLongShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TLongShortValueHashIterator(TLongShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TLongShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TLongShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TLongShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TLongShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TLongShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TLongShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongShortKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongShortHashIterator extends THashPrimitiveIterator implements TLongShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongShortHashMap we will be iterating over. + */ + TLongShortHashIterator(TLongShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongShortMap)) { + return false; + } + TLongShortMap that = (TLongShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + short val = in.readShort(); + put(key, val); + } + } +} // TLongShortHashMap diff --git a/src/gnu/trove/map/hash/TObjectByteHashMap.java b/src/gnu/trove/map/hash/TObjectByteHashMap.java new file mode 100644 index 0000000..fbcaf39 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectByteHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.iterator.TObjectByteIterator; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TByteFunction; +import gnu.trove.map.TObjectByteMap; +import gnu.trove.TByteCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and byte values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectByteHashMap extends TObjectHash implements TObjectByteMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectByteProcedure PUT_ALL_PROC = new TObjectByteProcedure() { + @Override + public boolean execute(K key, byte value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient byte[] _values; + + /** the value that represents null */ + protected byte no_entry_value; + + /** + * Creates a new TObjectByteHashMap instance with the default + * capacity and load factor. + */ + public TObjectByteHashMap() { + super(); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectByteHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectByteHashMap(int initialCapacity, float loadFactor, byte noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectByteHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectByteMap to be copied. + */ + public TObjectByteHashMap(TObjectByteMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectByteHashMap) { + TObjectByteHashMap hashmap = (TObjectByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + byte oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new byte[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + Object[] keys = _set; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public byte get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public byte put(K key, byte value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(K key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private byte doPut(byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public byte remove(Object key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectByteMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TByteValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectByteIterator iterator() { + return new TObjectByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(final K key, final byte adjust_amount, final byte put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + @Override + public void transformValues(TByteFunction function) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectByteMap)) { + return false; + } + TObjectByteMap that = (TObjectByteMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectByteIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + byte value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectByteHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectByteHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectByteHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectByteHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectByteHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectByteHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TByteValueCollection implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TObjectByteValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TObjectByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TObjectByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TObjectByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TObjectByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TObjectByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TObjectByteHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectByteValueHashIterator implements TByteIterator { + + protected THash _hash = TObjectByteHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectByteValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectByteHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectByteHashIterator extends TObjectHashIterator implements TObjectByteIterator { + + /** the collection being iterated over */ + private final TObjectByteHashMap _map; + + public TObjectByteHashIterator(TObjectByteHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeByte(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + byte val = in.readByte(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, byte value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectByteHashMap diff --git a/src/gnu/trove/map/hash/TObjectCharHashMap.java b/src/gnu/trove/map/hash/TObjectCharHashMap.java new file mode 100644 index 0000000..2644754 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectCharHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.iterator.TObjectCharIterator; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TCharFunction; +import gnu.trove.map.TObjectCharMap; +import gnu.trove.TCharCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and char values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectCharHashMap extends TObjectHash implements TObjectCharMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectCharProcedure PUT_ALL_PROC = new TObjectCharProcedure() { + @Override + public boolean execute(K key, char value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient char[] _values; + + /** the value that represents null */ + protected char no_entry_value; + + /** + * Creates a new TObjectCharHashMap instance with the default + * capacity and load factor. + */ + public TObjectCharHashMap() { + super(); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectCharHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectCharHashMap(int initialCapacity, float loadFactor, char noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectCharHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectCharMap to be copied. + */ + public TObjectCharHashMap(TObjectCharMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectCharHashMap) { + TObjectCharHashMap hashmap = (TObjectCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + char oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new char[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + Object[] keys = _set; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public char get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public char put(K key, char value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(K key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private char doPut(char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public char remove(Object key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectCharMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TCharValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectCharIterator iterator() { + return new TObjectCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(final K key, final char adjust_amount, final char put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + @Override + public void transformValues(TCharFunction function) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectCharMap)) { + return false; + } + TObjectCharMap that = (TObjectCharMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectCharIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + char value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectCharHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectCharHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectCharHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectCharHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectCharHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectCharHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TCharValueCollection implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TObjectCharValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TObjectCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TObjectCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TObjectCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TObjectCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TObjectCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TObjectCharHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectCharValueHashIterator implements TCharIterator { + + protected THash _hash = TObjectCharHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectCharValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectCharHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectCharHashIterator extends TObjectHashIterator implements TObjectCharIterator { + + /** the collection being iterated over */ + private final TObjectCharHashMap _map; + + public TObjectCharHashIterator(TObjectCharHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeChar(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + char val = in.readChar(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, char value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectCharHashMap diff --git a/src/gnu/trove/map/hash/TObjectDoubleHashMap.java b/src/gnu/trove/map/hash/TObjectDoubleHashMap.java new file mode 100644 index 0000000..e0bd61a --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectDoubleHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.iterator.TObjectDoubleIterator; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.map.TObjectDoubleMap; +import gnu.trove.TDoubleCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and double values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectDoubleHashMap extends TObjectHash implements TObjectDoubleMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectDoubleProcedure PUT_ALL_PROC = new TObjectDoubleProcedure() { + @Override + public boolean execute(K key, double value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient double[] _values; + + /** the value that represents null */ + protected double no_entry_value; + + /** + * Creates a new TObjectDoubleHashMap instance with the default + * capacity and load factor. + */ + public TObjectDoubleHashMap() { + super(); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TObjectDoubleHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime value + * at or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectDoubleHashMap(int initialCapacity, float loadFactor, double noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectDoubleHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectDoubleMap to be copied. + */ + public TObjectDoubleHashMap(TObjectDoubleMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectDoubleHashMap) { + TObjectDoubleHashMap hashmap = (TObjectDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + double oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new double[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + Object[] keys = _set; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public double get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public double put(K key, double value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(K key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private double doPut(double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public double remove(Object key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectDoubleMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TDoubleValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectDoubleIterator iterator() { + return new TObjectDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(final K key, final double adjust_amount, final double put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + @Override + public void transformValues(TDoubleFunction function) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectDoubleMap)) { + return false; + } + TObjectDoubleMap that = (TObjectDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectDoubleIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + double value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectDoubleHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectDoubleHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectDoubleHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectDoubleHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectDoubleHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectDoubleHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TDoubleValueCollection implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TObjectDoubleValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TObjectDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TObjectDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TObjectDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TObjectDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TObjectDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TObjectDoubleHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectDoubleValueHashIterator implements TDoubleIterator { + + protected THash _hash = TObjectDoubleHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectDoubleValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectDoubleHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectDoubleHashIterator extends TObjectHashIterator implements TObjectDoubleIterator { + + /** the collection being iterated over */ + private final TObjectDoubleHashMap _map; + + public TObjectDoubleHashIterator(TObjectDoubleHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + double val = in.readDouble(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, double value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectDoubleHashMap diff --git a/src/gnu/trove/map/hash/TObjectFloatHashMap.java b/src/gnu/trove/map/hash/TObjectFloatHashMap.java new file mode 100644 index 0000000..cde4272 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectFloatHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.iterator.TObjectFloatIterator; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TFloatFunction; +import gnu.trove.map.TObjectFloatMap; +import gnu.trove.TFloatCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and float values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectFloatHashMap extends TObjectHash implements TObjectFloatMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectFloatProcedure PUT_ALL_PROC = new TObjectFloatProcedure() { + @Override + public boolean execute(K key, float value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient float[] _values; + + /** the value that represents null */ + protected float no_entry_value; + + /** + * Creates a new TObjectFloatHashMap instance with the default + * capacity and load factor. + */ + public TObjectFloatHashMap() { + super(); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectFloatHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectFloatHashMap(int initialCapacity, float loadFactor, float noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectFloatHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectFloatMap to be copied. + */ + public TObjectFloatHashMap(TObjectFloatMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectFloatHashMap) { + TObjectFloatHashMap hashmap = (TObjectFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + float oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new float[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + Object[] keys = _set; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public float get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public float put(K key, float value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(K key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private float doPut(float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public float remove(Object key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectFloatMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TFloatValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectFloatIterator iterator() { + return new TObjectFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(final K key, final float adjust_amount, final float put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + @Override + public void transformValues(TFloatFunction function) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectFloatMap)) { + return false; + } + TObjectFloatMap that = (TObjectFloatMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectFloatIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + float value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectFloatHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectFloatHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectFloatHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectFloatHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectFloatHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectFloatHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TFloatValueCollection implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TObjectFloatValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TObjectFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TObjectFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TObjectFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TObjectFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TObjectFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TObjectFloatHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectFloatValueHashIterator implements TFloatIterator { + + protected THash _hash = TObjectFloatHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectFloatValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectFloatHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectFloatHashIterator extends TObjectHashIterator implements TObjectFloatIterator { + + /** the collection being iterated over */ + private final TObjectFloatHashMap _map; + + public TObjectFloatHashIterator(TObjectFloatHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + float val = in.readFloat(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, float value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectFloatHashMap diff --git a/src/gnu/trove/map/hash/TObjectIntHashMap.java b/src/gnu/trove/map/hash/TObjectIntHashMap.java new file mode 100644 index 0000000..3d38df8 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectIntHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.iterator.TObjectIntIterator; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TIntFunction; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.TIntCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and int values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectIntHashMap extends TObjectHash implements TObjectIntMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectIntProcedure PUT_ALL_PROC = new TObjectIntProcedure() { + @Override + public boolean execute(K key, int value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient int[] _values; + + /** the value that represents null */ + protected int no_entry_value; + + /** + * Creates a new TObjectIntHashMap instance with the default + * capacity and load factor. + */ + public TObjectIntHashMap() { + super(); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectIntHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectIntHashMap(int initialCapacity, float loadFactor, int noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectIntHashMap that contains the entries in the + * map passed to it. + * + * @param map + * the TObjectIntMap to be copied. + */ + public TObjectIntHashMap(TObjectIntMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectIntHashMap) { + TObjectIntHashMap hashmap = (TObjectIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + int oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new int[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + Object[] keys = _set; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public int get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public int put(K key, int value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(K key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private int doPut(int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public int remove(Object key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectIntMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TIntValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectIntIterator iterator() { + return new TObjectIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(final K key, final int adjust_amount, final int put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + @Override + public void transformValues(TIntFunction function) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectIntMap)) { + return false; + } + TObjectIntMap that = (TObjectIntMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectIntIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + int value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectIntHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectIntHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectIntHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectIntHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectIntHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectIntHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TIntValueCollection implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TObjectIntValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TObjectIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TObjectIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TObjectIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TObjectIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TObjectIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TObjectIntHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectIntValueHashIterator implements TIntIterator { + + protected THash _hash = TObjectIntHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectIntValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectIntHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectIntHashIterator extends TObjectHashIterator implements TObjectIntIterator { + + /** the collection being iterated over */ + private final TObjectIntHashMap _map; + + public TObjectIntHashIterator(TObjectIntHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeInt(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + int val = in.readInt(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, int value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectIntHashMap diff --git a/src/gnu/trove/map/hash/TObjectLongHashMap.java b/src/gnu/trove/map/hash/TObjectLongHashMap.java new file mode 100644 index 0000000..6c96d3e --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectLongHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.iterator.TObjectLongIterator; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TLongFunction; +import gnu.trove.map.TObjectLongMap; +import gnu.trove.TLongCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and long values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectLongHashMap extends TObjectHash implements TObjectLongMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectLongProcedure PUT_ALL_PROC = new TObjectLongProcedure() { + @Override + public boolean execute(K key, long value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient long[] _values; + + /** the value that represents null */ + protected long no_entry_value; + + /** + * Creates a new TObjectLongHashMap instance with the default + * capacity and load factor. + */ + public TObjectLongHashMap() { + super(); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectLongHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectLongHashMap(int initialCapacity, float loadFactor, long noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectLongHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectLongMap to be copied. + */ + public TObjectLongHashMap(TObjectLongMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectLongHashMap) { + TObjectLongHashMap hashmap = (TObjectLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + long oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new long[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + Object[] keys = _set; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public long get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public long put(K key, long value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(K key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private long doPut(long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public long remove(Object key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectLongMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TLongValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectLongIterator iterator() { + return new TObjectLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(final K key, final long adjust_amount, final long put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + @Override + public void transformValues(TLongFunction function) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectLongMap)) { + return false; + } + TObjectLongMap that = (TObjectLongMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectLongIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + long value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectLongHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectLongHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectLongHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectLongHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectLongHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectLongHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TLongValueCollection implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TObjectLongValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TObjectLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TObjectLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TObjectLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TObjectLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TObjectLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TObjectLongHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectLongValueHashIterator implements TLongIterator { + + protected THash _hash = TObjectLongHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectLongValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectLongHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectLongHashIterator extends TObjectHashIterator implements TObjectLongIterator { + + /** the collection being iterated over */ + private final TObjectLongHashMap _map; + + public TObjectLongHashIterator(TObjectLongHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeLong(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + long val = in.readLong(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, long value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectLongHashMap diff --git a/src/gnu/trove/map/hash/TObjectShortHashMap.java b/src/gnu/trove/map/hash/TObjectShortHashMap.java new file mode 100644 index 0000000..a2dc56b --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectShortHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.iterator.TObjectShortIterator; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TShortFunction; +import gnu.trove.map.TObjectShortMap; +import gnu.trove.TShortCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and short values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectShortHashMap extends TObjectHash implements TObjectShortMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectShortProcedure PUT_ALL_PROC = new TObjectShortProcedure() { + @Override + public boolean execute(K key, short value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient short[] _values; + + /** the value that represents null */ + protected short no_entry_value; + + /** + * Creates a new TObjectShortHashMap instance with the default + * capacity and load factor. + */ + public TObjectShortHashMap() { + super(); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectShortHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectShortHashMap(int initialCapacity, float loadFactor, short noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectShortHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectShortMap to be copied. + */ + public TObjectShortHashMap(TObjectShortMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectShortHashMap) { + TObjectShortHashMap hashmap = (TObjectShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + short oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new short[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + Object[] keys = _set; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public short get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public short put(K key, short value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(K key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private short doPut(short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public short remove(Object key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectShortMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TShortValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectShortIterator iterator() { + return new TObjectShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(final K key, final short adjust_amount, final short put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + @Override + public void transformValues(TShortFunction function) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectShortMap)) { + return false; + } + TObjectShortMap that = (TObjectShortMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectShortIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + short value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectShortHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectShortHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectShortHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectShortHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectShortHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectShortHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TShortValueCollection implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TObjectShortValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TObjectShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TObjectShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TObjectShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TObjectShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TObjectShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TObjectShortHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectShortValueHashIterator implements TShortIterator { + + protected THash _hash = TObjectShortHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectShortValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectShortHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectShortHashIterator extends TObjectHashIterator implements TObjectShortIterator { + + /** the collection being iterated over */ + private final TObjectShortHashMap _map; + + public TObjectShortHashIterator(TObjectShortHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeShort(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + short val = in.readShort(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, short value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectShortHashMap diff --git a/src/gnu/trove/map/hash/TShortByteHashMap.java b/src/gnu/trove/map/hash/TShortByteHashMap.java new file mode 100644 index 0000000..ae6e524 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortByteHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortByteHashMap extends TShortByteHash implements TShortByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TShortByteHashMap instance with the default + * capacity and load factor. + */ + public TShortByteHashMap() { + super(); + } + + /** + * Creates a new TShortByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TShortByteHashMap(int initialCapacity, float loadFactor, short noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a byte array containing the values. + */ + public TShortByteHashMap(short[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortByteMap that will be duplicated. + */ + public TShortByteHashMap(TShortByteMap map) { + super(map.size()); + if (map instanceof TShortByteHashMap) { + TShortByteHashMap hashmap = (TShortByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(short key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(short key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(short key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortByteMap map) { + ensureCapacity(map.size()); + TShortByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(short key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortByteIterator iterator() { + return new TShortByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortByteProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortByteKeyHashIterator(TShortByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TShortByteValueHashIterator(TShortByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TShortByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TShortByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TShortByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TShortByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TShortByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TShortByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortByteKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortByteHashIterator extends THashPrimitiveIterator implements TShortByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortByteHashMap we will be iterating over. + */ + TShortByteHashIterator(TShortByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortByteMap)) { + return false; + } + TShortByteMap that = (TShortByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + byte val = in.readByte(); + put(key, val); + } + } +} // TShortByteHashMap diff --git a/src/gnu/trove/map/hash/TShortCharHashMap.java b/src/gnu/trove/map/hash/TShortCharHashMap.java new file mode 100644 index 0000000..af15ef2 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortCharHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortCharHashMap extends TShortCharHash implements TShortCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TShortCharHashMap instance with the default + * capacity and load factor. + */ + public TShortCharHashMap() { + super(); + } + + /** + * Creates a new TShortCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TShortCharHashMap(int initialCapacity, float loadFactor, short noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a char array containing the values. + */ + public TShortCharHashMap(short[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortCharMap that will be duplicated. + */ + public TShortCharHashMap(TShortCharMap map) { + super(map.size()); + if (map instanceof TShortCharHashMap) { + TShortCharHashMap hashmap = (TShortCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(short key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(short key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(short key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortCharMap map) { + ensureCapacity(map.size()); + TShortCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(short key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortCharIterator iterator() { + return new TShortCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortCharProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(short key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortCharKeyHashIterator(TShortCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TShortCharValueHashIterator(TShortCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TShortCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TShortCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TShortCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TShortCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TShortCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TShortCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortCharKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortCharHashIterator extends THashPrimitiveIterator implements TShortCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortCharHashMap we will be iterating over. + */ + TShortCharHashIterator(TShortCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortCharMap)) { + return false; + } + TShortCharMap that = (TShortCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + char val = in.readChar(); + put(key, val); + } + } +} // TShortCharHashMap diff --git a/src/gnu/trove/map/hash/TShortDoubleHashMap.java b/src/gnu/trove/map/hash/TShortDoubleHashMap.java new file mode 100644 index 0000000..0399e8d --- /dev/null +++ b/src/gnu/trove/map/hash/TShortDoubleHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortDoubleHashMap extends TShortDoubleHash implements TShortDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TShortDoubleHashMap instance with the default + * capacity and load factor. + */ + public TShortDoubleHashMap() { + super(); + } + + /** + * Creates a new TShortDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TShortDoubleHashMap(int initialCapacity, float loadFactor, short noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a double array containing the values. + */ + public TShortDoubleHashMap(short[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortDoubleMap that will be duplicated. + */ + public TShortDoubleHashMap(TShortDoubleMap map) { + super(map.size()); + if (map instanceof TShortDoubleHashMap) { + TShortDoubleHashMap hashmap = (TShortDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(short key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(short key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(short key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortDoubleMap map) { + ensureCapacity(map.size()); + TShortDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(short key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortDoubleIterator iterator() { + return new TShortDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortDoubleProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(short key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortDoubleKeyHashIterator(TShortDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TShortDoubleValueHashIterator(TShortDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TShortDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TShortDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TShortDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TShortDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TShortDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TShortDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortDoubleKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortDoubleHashIterator extends THashPrimitiveIterator implements TShortDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortDoubleHashMap we will be iterating over. + */ + TShortDoubleHashIterator(TShortDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortDoubleMap)) { + return false; + } + TShortDoubleMap that = (TShortDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + double val = in.readDouble(); + put(key, val); + } + } +} // TShortDoubleHashMap diff --git a/src/gnu/trove/map/hash/TShortFloatHashMap.java b/src/gnu/trove/map/hash/TShortFloatHashMap.java new file mode 100644 index 0000000..a1d1792 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortFloatHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortFloatHashMap extends TShortFloatHash implements TShortFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TShortFloatHashMap instance with the default + * capacity and load factor. + */ + public TShortFloatHashMap() { + super(); + } + + /** + * Creates a new TShortFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TShortFloatHashMap(int initialCapacity, float loadFactor, short noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a float array containing the values. + */ + public TShortFloatHashMap(short[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortFloatMap that will be duplicated. + */ + public TShortFloatHashMap(TShortFloatMap map) { + super(map.size()); + if (map instanceof TShortFloatHashMap) { + TShortFloatHashMap hashmap = (TShortFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(short key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(short key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(short key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortFloatMap map) { + ensureCapacity(map.size()); + TShortFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(short key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortFloatIterator iterator() { + return new TShortFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortFloatProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(short key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortFloatKeyHashIterator(TShortFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TShortFloatValueHashIterator(TShortFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TShortFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TShortFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TShortFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TShortFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TShortFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TShortFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortFloatKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortFloatHashIterator extends THashPrimitiveIterator implements TShortFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortFloatHashMap we will be iterating over. + */ + TShortFloatHashIterator(TShortFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortFloatMap)) { + return false; + } + TShortFloatMap that = (TShortFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + float val = in.readFloat(); + put(key, val); + } + } +} // TShortFloatHashMap diff --git a/src/gnu/trove/map/hash/TShortIntHashMap.java b/src/gnu/trove/map/hash/TShortIntHashMap.java new file mode 100644 index 0000000..29ba707 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortIntHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortIntHashMap extends TShortIntHash implements TShortIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TShortIntHashMap instance with the default + * capacity and load factor. + */ + public TShortIntHashMap() { + super(); + } + + /** + * Creates a new TShortIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TShortIntHashMap(int initialCapacity, float loadFactor, short noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a int array containing the values. + */ + public TShortIntHashMap(short[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortIntMap that will be duplicated. + */ + public TShortIntHashMap(TShortIntMap map) { + super(map.size()); + if (map instanceof TShortIntHashMap) { + TShortIntHashMap hashmap = (TShortIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(short key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(short key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(short key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortIntMap map) { + ensureCapacity(map.size()); + TShortIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(short key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortIntIterator iterator() { + return new TShortIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortIntProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(short key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortIntKeyHashIterator(TShortIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TShortIntValueHashIterator(TShortIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TShortIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TShortIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TShortIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TShortIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TShortIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TShortIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortIntKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortIntHashIterator extends THashPrimitiveIterator implements TShortIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortIntHashMap we will be iterating over. + */ + TShortIntHashIterator(TShortIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortIntMap)) { + return false; + } + TShortIntMap that = (TShortIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + int val = in.readInt(); + put(key, val); + } + } +} // TShortIntHashMap diff --git a/src/gnu/trove/map/hash/TShortLongHashMap.java b/src/gnu/trove/map/hash/TShortLongHashMap.java new file mode 100644 index 0000000..e80c1d6 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortLongHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortLongHashMap extends TShortLongHash implements TShortLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TShortLongHashMap instance with the default + * capacity and load factor. + */ + public TShortLongHashMap() { + super(); + } + + /** + * Creates a new TShortLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TShortLongHashMap(int initialCapacity, float loadFactor, short noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a long array containing the values. + */ + public TShortLongHashMap(short[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortLongMap that will be duplicated. + */ + public TShortLongHashMap(TShortLongMap map) { + super(map.size()); + if (map instanceof TShortLongHashMap) { + TShortLongHashMap hashmap = (TShortLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(short key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(short key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(short key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortLongMap map) { + ensureCapacity(map.size()); + TShortLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(short key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortLongIterator iterator() { + return new TShortLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortLongProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(short key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortLongKeyHashIterator(TShortLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TShortLongValueHashIterator(TShortLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TShortLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TShortLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TShortLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TShortLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TShortLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TShortLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortLongKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortLongHashIterator extends THashPrimitiveIterator implements TShortLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortLongHashMap we will be iterating over. + */ + TShortLongHashIterator(TShortLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortLongMap)) { + return false; + } + TShortLongMap that = (TShortLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + long val = in.readLong(); + put(key, val); + } + } +} // TShortLongHashMap diff --git a/src/gnu/trove/map/hash/TShortObjectHashMap.java b/src/gnu/trove/map/hash/TShortObjectHashMap.java new file mode 100644 index 0000000..b5842d6 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TShortObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TShortObjectProcedure; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.iterator.TShortObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TShortSet; +import gnu.trove.TShortCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for short keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TShortObjectHashMap extends TShortHash implements TShortObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TShortObjectProcedure PUT_ALL_PROC = new TShortObjectProcedure() { + @Override + public boolean execute(short key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected short no_entry_key; + + /** + * Creates a new TShortObjectHashMap instance with the default + * capacity and load factor. + */ + public TShortObjectHashMap() { + super(); + } + + /** + * Creates a new TShortObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TShortObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TShortObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TShortObjectHashMap(int initialCapacity, float loadFactor, short noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TShortObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TShortObjectMap to be copied. + */ + public TShortObjectHashMap(TShortObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public short getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(short key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(short key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(short key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(short key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public short[] keys() { + short[] keys = new short[size()]; + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public short[] keys(short[] dest) { + if (dest.length < _size) { + dest = new short[_size]; + } + + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TShortObjectIterator iterator() { + return new TShortObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TShortObjectProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TShortObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortObjectMap)) { + return false; + } + TShortObjectMap that = (TShortObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TShortObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + short key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortHashIterator(TShortObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return null != TShortObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TShortObjectHashMap.this.containsKey(((Short) element).shortValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + if (collection == this) { + return true; + } + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TShortHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** the collection on which the iterator operates */ + private final TShortHash _hash; + + /** {@inheritDoc} */ + public TShortHashIterator(TShortHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TShortObjectValueHashIterator(TShortObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TShortObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TShortObjectHashMap _map; + + public TShortObjectValueHashIterator(TShortObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TShortObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TShortObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TShortObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TShortObjectHashIterator extends THashPrimitiveIterator implements TShortObjectIterator { + + /** the collection being iterated over */ + private final TShortObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TShortObjectHashIterator(TShortObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TShortObjectHashMap diff --git a/src/gnu/trove/map/hash/TShortShortHashMap.java b/src/gnu/trove/map/hash/TShortShortHashMap.java new file mode 100644 index 0000000..a7c2571 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortShortHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortShortHashMap extends TShortShortHash implements TShortShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TShortShortHashMap instance with the default + * capacity and load factor. + */ + public TShortShortHashMap() { + super(); + } + + /** + * Creates a new TShortShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TShortShortHashMap(int initialCapacity, float loadFactor, short noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a short array containing the values. + */ + public TShortShortHashMap(short[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortShortMap that will be duplicated. + */ + public TShortShortHashMap(TShortShortMap map) { + super(map.size()); + if (map instanceof TShortShortHashMap) { + TShortShortHashMap hashmap = (TShortShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(short key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(short key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(short key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortShortMap map) { + ensureCapacity(map.size()); + TShortShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(short key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortShortIterator iterator() { + return new TShortShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortShortProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(short key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortShortKeyHashIterator(TShortShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortShortValueHashIterator(TShortShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortShortKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortShortHashIterator extends THashPrimitiveIterator implements TShortShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortShortHashMap we will be iterating over. + */ + TShortShortHashIterator(TShortShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortShortMap)) { + return false; + } + TShortShortMap that = (TShortShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + short val = in.readShort(); + put(key, val); + } + } +} // TShortShortHashMap diff --git a/src/gnu/trove/procedure/TByteByteProcedure.java b/src/gnu/trove/procedure/TByteByteProcedure.java new file mode 100644 index 0000000..7db91f6 --- /dev/null +++ b/src/gnu/trove/procedure/TByteByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and byte. + */ +public interface TByteByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, byte b); +} diff --git a/src/gnu/trove/procedure/TByteCharProcedure.java b/src/gnu/trove/procedure/TByteCharProcedure.java new file mode 100644 index 0000000..335f252 --- /dev/null +++ b/src/gnu/trove/procedure/TByteCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and char. + */ +public interface TByteCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, char b); +} diff --git a/src/gnu/trove/procedure/TByteDoubleProcedure.java b/src/gnu/trove/procedure/TByteDoubleProcedure.java new file mode 100644 index 0000000..ee037f6 --- /dev/null +++ b/src/gnu/trove/procedure/TByteDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and double. + */ +public interface TByteDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, double b); +} diff --git a/src/gnu/trove/procedure/TByteFloatProcedure.java b/src/gnu/trove/procedure/TByteFloatProcedure.java new file mode 100644 index 0000000..268bfbb --- /dev/null +++ b/src/gnu/trove/procedure/TByteFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and float. + */ +public interface TByteFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, float b); +} diff --git a/src/gnu/trove/procedure/TByteIntProcedure.java b/src/gnu/trove/procedure/TByteIntProcedure.java new file mode 100644 index 0000000..20318fb --- /dev/null +++ b/src/gnu/trove/procedure/TByteIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and int. + */ +public interface TByteIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, int b); +} diff --git a/src/gnu/trove/procedure/TByteLongProcedure.java b/src/gnu/trove/procedure/TByteLongProcedure.java new file mode 100644 index 0000000..b8525ae --- /dev/null +++ b/src/gnu/trove/procedure/TByteLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and long. + */ +public interface TByteLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, long b); +} diff --git a/src/gnu/trove/procedure/TByteObjectProcedure.java b/src/gnu/trove/procedure/TByteObjectProcedure.java new file mode 100644 index 0000000..facc4b4 --- /dev/null +++ b/src/gnu/trove/procedure/TByteObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and Object. + */ +public interface TByteObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, T b); +} diff --git a/src/gnu/trove/procedure/TByteProcedure.java b/src/gnu/trove/procedure/TByteProcedure.java new file mode 100644 index 0000000..318dd76 --- /dev/null +++ b/src/gnu/trove/procedure/TByteProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one byte parameter. + */ +public interface TByteProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type byte + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte value); +} diff --git a/src/gnu/trove/procedure/TByteShortProcedure.java b/src/gnu/trove/procedure/TByteShortProcedure.java new file mode 100644 index 0000000..a54d2ec --- /dev/null +++ b/src/gnu/trove/procedure/TByteShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and short. + */ +public interface TByteShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, short b); +} diff --git a/src/gnu/trove/procedure/TCharByteProcedure.java b/src/gnu/trove/procedure/TCharByteProcedure.java new file mode 100644 index 0000000..ff7a99e --- /dev/null +++ b/src/gnu/trove/procedure/TCharByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and byte. + */ +public interface TCharByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, byte b); +} diff --git a/src/gnu/trove/procedure/TCharCharProcedure.java b/src/gnu/trove/procedure/TCharCharProcedure.java new file mode 100644 index 0000000..c00cd73 --- /dev/null +++ b/src/gnu/trove/procedure/TCharCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and char. + */ +public interface TCharCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, char b); +} diff --git a/src/gnu/trove/procedure/TCharDoubleProcedure.java b/src/gnu/trove/procedure/TCharDoubleProcedure.java new file mode 100644 index 0000000..26bc854 --- /dev/null +++ b/src/gnu/trove/procedure/TCharDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and double. + */ +public interface TCharDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, double b); +} diff --git a/src/gnu/trove/procedure/TCharFloatProcedure.java b/src/gnu/trove/procedure/TCharFloatProcedure.java new file mode 100644 index 0000000..b17249c --- /dev/null +++ b/src/gnu/trove/procedure/TCharFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and float. + */ +public interface TCharFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, float b); +} diff --git a/src/gnu/trove/procedure/TCharIntProcedure.java b/src/gnu/trove/procedure/TCharIntProcedure.java new file mode 100644 index 0000000..ec40420 --- /dev/null +++ b/src/gnu/trove/procedure/TCharIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and int. + */ +public interface TCharIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, int b); +} diff --git a/src/gnu/trove/procedure/TCharLongProcedure.java b/src/gnu/trove/procedure/TCharLongProcedure.java new file mode 100644 index 0000000..852835f --- /dev/null +++ b/src/gnu/trove/procedure/TCharLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and long. + */ +public interface TCharLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, long b); +} diff --git a/src/gnu/trove/procedure/TCharObjectProcedure.java b/src/gnu/trove/procedure/TCharObjectProcedure.java new file mode 100644 index 0000000..9b83fcf --- /dev/null +++ b/src/gnu/trove/procedure/TCharObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and Object. + */ +public interface TCharObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, T b); +} diff --git a/src/gnu/trove/procedure/TCharProcedure.java b/src/gnu/trove/procedure/TCharProcedure.java new file mode 100644 index 0000000..53b156b --- /dev/null +++ b/src/gnu/trove/procedure/TCharProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one char parameter. + */ +public interface TCharProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type char + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char value); +} diff --git a/src/gnu/trove/procedure/TCharShortProcedure.java b/src/gnu/trove/procedure/TCharShortProcedure.java new file mode 100644 index 0000000..b464a15 --- /dev/null +++ b/src/gnu/trove/procedure/TCharShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and short. + */ +public interface TCharShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, short b); +} diff --git a/src/gnu/trove/procedure/TDoubleByteProcedure.java b/src/gnu/trove/procedure/TDoubleByteProcedure.java new file mode 100644 index 0000000..419d5a8 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and byte. + */ +public interface TDoubleByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, byte b); +} diff --git a/src/gnu/trove/procedure/TDoubleCharProcedure.java b/src/gnu/trove/procedure/TDoubleCharProcedure.java new file mode 100644 index 0000000..15f930a --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and char. + */ +public interface TDoubleCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, char b); +} diff --git a/src/gnu/trove/procedure/TDoubleDoubleProcedure.java b/src/gnu/trove/procedure/TDoubleDoubleProcedure.java new file mode 100644 index 0000000..2499501 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and double. + */ +public interface TDoubleDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, double b); +} diff --git a/src/gnu/trove/procedure/TDoubleFloatProcedure.java b/src/gnu/trove/procedure/TDoubleFloatProcedure.java new file mode 100644 index 0000000..a2cda60 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and float. + */ +public interface TDoubleFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, float b); +} diff --git a/src/gnu/trove/procedure/TDoubleIntProcedure.java b/src/gnu/trove/procedure/TDoubleIntProcedure.java new file mode 100644 index 0000000..758e2e8 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and int. + */ +public interface TDoubleIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, int b); +} diff --git a/src/gnu/trove/procedure/TDoubleLongProcedure.java b/src/gnu/trove/procedure/TDoubleLongProcedure.java new file mode 100644 index 0000000..559199d --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and long. + */ +public interface TDoubleLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, long b); +} diff --git a/src/gnu/trove/procedure/TDoubleObjectProcedure.java b/src/gnu/trove/procedure/TDoubleObjectProcedure.java new file mode 100644 index 0000000..c585c7b --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and Object. + */ +public interface TDoubleObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, T b); +} diff --git a/src/gnu/trove/procedure/TDoubleProcedure.java b/src/gnu/trove/procedure/TDoubleProcedure.java new file mode 100644 index 0000000..f7f0779 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one double parameter. + */ +public interface TDoubleProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type double + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double value); +} diff --git a/src/gnu/trove/procedure/TDoubleShortProcedure.java b/src/gnu/trove/procedure/TDoubleShortProcedure.java new file mode 100644 index 0000000..582ad4b --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and short. + */ +public interface TDoubleShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, short b); +} diff --git a/src/gnu/trove/procedure/TFloatByteProcedure.java b/src/gnu/trove/procedure/TFloatByteProcedure.java new file mode 100644 index 0000000..8274243 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and byte. + */ +public interface TFloatByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, byte b); +} diff --git a/src/gnu/trove/procedure/TFloatCharProcedure.java b/src/gnu/trove/procedure/TFloatCharProcedure.java new file mode 100644 index 0000000..443b4d3 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and char. + */ +public interface TFloatCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, char b); +} diff --git a/src/gnu/trove/procedure/TFloatDoubleProcedure.java b/src/gnu/trove/procedure/TFloatDoubleProcedure.java new file mode 100644 index 0000000..5fa8ec9 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and double. + */ +public interface TFloatDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, double b); +} diff --git a/src/gnu/trove/procedure/TFloatFloatProcedure.java b/src/gnu/trove/procedure/TFloatFloatProcedure.java new file mode 100644 index 0000000..58f7564 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and float. + */ +public interface TFloatFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, float b); +} diff --git a/src/gnu/trove/procedure/TFloatIntProcedure.java b/src/gnu/trove/procedure/TFloatIntProcedure.java new file mode 100644 index 0000000..30637c3 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and int. + */ +public interface TFloatIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, int b); +} diff --git a/src/gnu/trove/procedure/TFloatLongProcedure.java b/src/gnu/trove/procedure/TFloatLongProcedure.java new file mode 100644 index 0000000..1dfc596 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and long. + */ +public interface TFloatLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, long b); +} diff --git a/src/gnu/trove/procedure/TFloatObjectProcedure.java b/src/gnu/trove/procedure/TFloatObjectProcedure.java new file mode 100644 index 0000000..d0fd95e --- /dev/null +++ b/src/gnu/trove/procedure/TFloatObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and Object. + */ +public interface TFloatObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, T b); +} diff --git a/src/gnu/trove/procedure/TFloatProcedure.java b/src/gnu/trove/procedure/TFloatProcedure.java new file mode 100644 index 0000000..7732a1a --- /dev/null +++ b/src/gnu/trove/procedure/TFloatProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one float parameter. + */ +public interface TFloatProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type float + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float value); +} diff --git a/src/gnu/trove/procedure/TFloatShortProcedure.java b/src/gnu/trove/procedure/TFloatShortProcedure.java new file mode 100644 index 0000000..fc4fb5b --- /dev/null +++ b/src/gnu/trove/procedure/TFloatShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and short. + */ +public interface TFloatShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, short b); +} diff --git a/src/gnu/trove/procedure/TIntByteProcedure.java b/src/gnu/trove/procedure/TIntByteProcedure.java new file mode 100644 index 0000000..453045b --- /dev/null +++ b/src/gnu/trove/procedure/TIntByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and byte. + */ +public interface TIntByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, byte b); +} diff --git a/src/gnu/trove/procedure/TIntCharProcedure.java b/src/gnu/trove/procedure/TIntCharProcedure.java new file mode 100644 index 0000000..017a3b5 --- /dev/null +++ b/src/gnu/trove/procedure/TIntCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and char. + */ +public interface TIntCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, char b); +} diff --git a/src/gnu/trove/procedure/TIntDoubleProcedure.java b/src/gnu/trove/procedure/TIntDoubleProcedure.java new file mode 100644 index 0000000..a02577f --- /dev/null +++ b/src/gnu/trove/procedure/TIntDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and double. + */ +public interface TIntDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, double b); +} diff --git a/src/gnu/trove/procedure/TIntFloatProcedure.java b/src/gnu/trove/procedure/TIntFloatProcedure.java new file mode 100644 index 0000000..8d2045f --- /dev/null +++ b/src/gnu/trove/procedure/TIntFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and float. + */ +public interface TIntFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, float b); +} diff --git a/src/gnu/trove/procedure/TIntIntProcedure.java b/src/gnu/trove/procedure/TIntIntProcedure.java new file mode 100644 index 0000000..72b328c --- /dev/null +++ b/src/gnu/trove/procedure/TIntIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and int. + */ +public interface TIntIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, int b); +} diff --git a/src/gnu/trove/procedure/TIntLongProcedure.java b/src/gnu/trove/procedure/TIntLongProcedure.java new file mode 100644 index 0000000..f4dd5d4 --- /dev/null +++ b/src/gnu/trove/procedure/TIntLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and long. + */ +public interface TIntLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, long b); +} diff --git a/src/gnu/trove/procedure/TIntObjectProcedure.java b/src/gnu/trove/procedure/TIntObjectProcedure.java new file mode 100644 index 0000000..d0311d1 --- /dev/null +++ b/src/gnu/trove/procedure/TIntObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and Object. + */ +public interface TIntObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, T b); +} diff --git a/src/gnu/trove/procedure/TIntProcedure.java b/src/gnu/trove/procedure/TIntProcedure.java new file mode 100644 index 0000000..12a2958 --- /dev/null +++ b/src/gnu/trove/procedure/TIntProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one int parameter. + */ +public interface TIntProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int value); +} diff --git a/src/gnu/trove/procedure/TIntShortProcedure.java b/src/gnu/trove/procedure/TIntShortProcedure.java new file mode 100644 index 0000000..4b52a07 --- /dev/null +++ b/src/gnu/trove/procedure/TIntShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and short. + */ +public interface TIntShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, short b); +} diff --git a/src/gnu/trove/procedure/TLongByteProcedure.java b/src/gnu/trove/procedure/TLongByteProcedure.java new file mode 100644 index 0000000..cc30058 --- /dev/null +++ b/src/gnu/trove/procedure/TLongByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and byte. + */ +public interface TLongByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, byte b); +} diff --git a/src/gnu/trove/procedure/TLongCharProcedure.java b/src/gnu/trove/procedure/TLongCharProcedure.java new file mode 100644 index 0000000..d115f1a --- /dev/null +++ b/src/gnu/trove/procedure/TLongCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and char. + */ +public interface TLongCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, char b); +} diff --git a/src/gnu/trove/procedure/TLongDoubleProcedure.java b/src/gnu/trove/procedure/TLongDoubleProcedure.java new file mode 100644 index 0000000..90667c2 --- /dev/null +++ b/src/gnu/trove/procedure/TLongDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and double. + */ +public interface TLongDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, double b); +} diff --git a/src/gnu/trove/procedure/TLongFloatProcedure.java b/src/gnu/trove/procedure/TLongFloatProcedure.java new file mode 100644 index 0000000..0651631 --- /dev/null +++ b/src/gnu/trove/procedure/TLongFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and float. + */ +public interface TLongFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, float b); +} diff --git a/src/gnu/trove/procedure/TLongIntProcedure.java b/src/gnu/trove/procedure/TLongIntProcedure.java new file mode 100644 index 0000000..c500d50 --- /dev/null +++ b/src/gnu/trove/procedure/TLongIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and int. + */ +public interface TLongIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, int b); +} diff --git a/src/gnu/trove/procedure/TLongLongProcedure.java b/src/gnu/trove/procedure/TLongLongProcedure.java new file mode 100644 index 0000000..a00d6e3 --- /dev/null +++ b/src/gnu/trove/procedure/TLongLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and long. + */ +public interface TLongLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, long b); +} diff --git a/src/gnu/trove/procedure/TLongObjectProcedure.java b/src/gnu/trove/procedure/TLongObjectProcedure.java new file mode 100644 index 0000000..4f2b50d --- /dev/null +++ b/src/gnu/trove/procedure/TLongObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and Object. + */ +public interface TLongObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, T b); +} diff --git a/src/gnu/trove/procedure/TLongProcedure.java b/src/gnu/trove/procedure/TLongProcedure.java new file mode 100644 index 0000000..86fe384 --- /dev/null +++ b/src/gnu/trove/procedure/TLongProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one long parameter. + */ +public interface TLongProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type long + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long value); +} diff --git a/src/gnu/trove/procedure/TLongShortProcedure.java b/src/gnu/trove/procedure/TLongShortProcedure.java new file mode 100644 index 0000000..6ceda35 --- /dev/null +++ b/src/gnu/trove/procedure/TLongShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and short. + */ +public interface TLongShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, short b); +} diff --git a/src/gnu/trove/procedure/TObjectByteProcedure.java b/src/gnu/trove/procedure/TObjectByteProcedure.java new file mode 100644 index 0000000..b6f0918 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and byte. + */ +public interface TObjectByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, byte b); +} diff --git a/src/gnu/trove/procedure/TObjectCharProcedure.java b/src/gnu/trove/procedure/TObjectCharProcedure.java new file mode 100644 index 0000000..74a0528 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and char. + */ +public interface TObjectCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, char b); +} diff --git a/src/gnu/trove/procedure/TObjectDoubleProcedure.java b/src/gnu/trove/procedure/TObjectDoubleProcedure.java new file mode 100644 index 0000000..4eaf03d --- /dev/null +++ b/src/gnu/trove/procedure/TObjectDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and double. + */ +public interface TObjectDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, double b); +} diff --git a/src/gnu/trove/procedure/TObjectFloatProcedure.java b/src/gnu/trove/procedure/TObjectFloatProcedure.java new file mode 100644 index 0000000..69b93f3 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and float. + */ +public interface TObjectFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, float b); +} diff --git a/src/gnu/trove/procedure/TObjectIntProcedure.java b/src/gnu/trove/procedure/TObjectIntProcedure.java new file mode 100644 index 0000000..520f045 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and int. + */ +public interface TObjectIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, int b); +} diff --git a/src/gnu/trove/procedure/TObjectLongProcedure.java b/src/gnu/trove/procedure/TObjectLongProcedure.java new file mode 100644 index 0000000..4510e2a --- /dev/null +++ b/src/gnu/trove/procedure/TObjectLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and long. + */ +public interface TObjectLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, long b); +} diff --git a/src/gnu/trove/procedure/TObjectObjectProcedure.java b/src/gnu/trove/procedure/TObjectObjectProcedure.java new file mode 100644 index 0000000..60d226f --- /dev/null +++ b/src/gnu/trove/procedure/TObjectObjectProcedure.java @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +/** + * Interface for procedures that take two Object parameters. + *

+ * Created: Mon Nov 5 22:03:30 2001 + * + * @author Eric D. Friedman + * @version $Id: TObjectObjectProcedure.java,v 1.1.2.1 2009/09/06 17:02:20 + * upholderoftruth Exp $ + */ + +public interface TObjectObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, V b); +}// TObjectObjectProcedure diff --git a/src/gnu/trove/procedure/TObjectProcedure.java b/src/gnu/trove/procedure/TObjectProcedure.java new file mode 100644 index 0000000..4dff70d --- /dev/null +++ b/src/gnu/trove/procedure/TObjectProcedure.java @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +/** + * Interface for procedures with one Object parameter. + * + * Created: Mon Nov 5 21:45:49 2001 + * + * @author Eric D. Friedman + * @version $Id: TObjectProcedure.java,v 1.1.2.1 2009/09/02 21:52:33 + * upholderoftruth Exp $ + */ + +public interface TObjectProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param object + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(T object); +}// TObjectProcedure diff --git a/src/gnu/trove/procedure/TObjectShortProcedure.java b/src/gnu/trove/procedure/TObjectShortProcedure.java new file mode 100644 index 0000000..41f080a --- /dev/null +++ b/src/gnu/trove/procedure/TObjectShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and short. + */ +public interface TObjectShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, short b); +} diff --git a/src/gnu/trove/procedure/TShortByteProcedure.java b/src/gnu/trove/procedure/TShortByteProcedure.java new file mode 100644 index 0000000..e63ef7f --- /dev/null +++ b/src/gnu/trove/procedure/TShortByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and byte. + */ +public interface TShortByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, byte b); +} diff --git a/src/gnu/trove/procedure/TShortCharProcedure.java b/src/gnu/trove/procedure/TShortCharProcedure.java new file mode 100644 index 0000000..d887290 --- /dev/null +++ b/src/gnu/trove/procedure/TShortCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and char. + */ +public interface TShortCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, char b); +} diff --git a/src/gnu/trove/procedure/TShortDoubleProcedure.java b/src/gnu/trove/procedure/TShortDoubleProcedure.java new file mode 100644 index 0000000..f9ff1a1 --- /dev/null +++ b/src/gnu/trove/procedure/TShortDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and double. + */ +public interface TShortDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, double b); +} diff --git a/src/gnu/trove/procedure/TShortFloatProcedure.java b/src/gnu/trove/procedure/TShortFloatProcedure.java new file mode 100644 index 0000000..87d2f53 --- /dev/null +++ b/src/gnu/trove/procedure/TShortFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and float. + */ +public interface TShortFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, float b); +} diff --git a/src/gnu/trove/procedure/TShortIntProcedure.java b/src/gnu/trove/procedure/TShortIntProcedure.java new file mode 100644 index 0000000..8b1c1a9 --- /dev/null +++ b/src/gnu/trove/procedure/TShortIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and int. + */ +public interface TShortIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, int b); +} diff --git a/src/gnu/trove/procedure/TShortLongProcedure.java b/src/gnu/trove/procedure/TShortLongProcedure.java new file mode 100644 index 0000000..827c50b --- /dev/null +++ b/src/gnu/trove/procedure/TShortLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and long. + */ +public interface TShortLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, long b); +} diff --git a/src/gnu/trove/procedure/TShortObjectProcedure.java b/src/gnu/trove/procedure/TShortObjectProcedure.java new file mode 100644 index 0000000..91b8a22 --- /dev/null +++ b/src/gnu/trove/procedure/TShortObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and Object. + */ +public interface TShortObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, T b); +} diff --git a/src/gnu/trove/procedure/TShortProcedure.java b/src/gnu/trove/procedure/TShortProcedure.java new file mode 100644 index 0000000..96ec21e --- /dev/null +++ b/src/gnu/trove/procedure/TShortProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one short parameter. + */ +public interface TShortProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type short + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short value); +} diff --git a/src/gnu/trove/procedure/TShortShortProcedure.java b/src/gnu/trove/procedure/TShortShortProcedure.java new file mode 100644 index 0000000..0b19c7a --- /dev/null +++ b/src/gnu/trove/procedure/TShortShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and short. + */ +public interface TShortShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, short b); +} diff --git a/src/gnu/trove/procedure/array/ToObjectArrayProceedure.java b/src/gnu/trove/procedure/array/ToObjectArrayProceedure.java new file mode 100644 index 0000000..583cb6a --- /dev/null +++ b/src/gnu/trove/procedure/array/ToObjectArrayProceedure.java @@ -0,0 +1,47 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure.array; + +import gnu.trove.procedure.TObjectProcedure; + +/** + * A procedure which stores each value it receives into a target array. + *

+ * Created: Sat Jan 12 10:13:42 2002 + * + * @author Eric D. Friedman + * @version $Id: ToObjectArrayProceedure.java,v 1.1.2.1 2009/09/02 21:52:33 + * upholderoftruth Exp $ + */ + +public final class ToObjectArrayProceedure implements TObjectProcedure { + + private final T[] target; + private int pos = 0; + + public ToObjectArrayProceedure(final T[] target) { + this.target = target; + } + + @Override + public final boolean execute(T value) { + target[pos++] = value; + return true; + } +} // ToObjectArrayProcedure \ No newline at end of file diff --git a/src/gnu/trove/queue/TByteQueue.java b/src/gnu/trove/queue/TByteQueue.java new file mode 100644 index 0000000..3c9bca5 --- /dev/null +++ b/src/gnu/trove/queue/TByteQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TByteCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TByteQueue extends TByteCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public byte element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(byte e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public byte peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public byte poll(); +} diff --git a/src/gnu/trove/queue/TCharQueue.java b/src/gnu/trove/queue/TCharQueue.java new file mode 100644 index 0000000..3713793 --- /dev/null +++ b/src/gnu/trove/queue/TCharQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TCharCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TCharQueue extends TCharCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public char element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(char e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public char peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public char poll(); +} diff --git a/src/gnu/trove/queue/TDoubleQueue.java b/src/gnu/trove/queue/TDoubleQueue.java new file mode 100644 index 0000000..78474c2 --- /dev/null +++ b/src/gnu/trove/queue/TDoubleQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TDoubleCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TDoubleQueue extends TDoubleCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public double element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(double e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public double peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public double poll(); +} diff --git a/src/gnu/trove/queue/TFloatQueue.java b/src/gnu/trove/queue/TFloatQueue.java new file mode 100644 index 0000000..fa5b977 --- /dev/null +++ b/src/gnu/trove/queue/TFloatQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TFloatCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TFloatQueue extends TFloatCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public float element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(float e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public float peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public float poll(); +} diff --git a/src/gnu/trove/queue/TIntQueue.java b/src/gnu/trove/queue/TIntQueue.java new file mode 100644 index 0000000..5926dbe --- /dev/null +++ b/src/gnu/trove/queue/TIntQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TIntCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TIntQueue extends TIntCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public int element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(int e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public int peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public int poll(); +} diff --git a/src/gnu/trove/queue/TLongQueue.java b/src/gnu/trove/queue/TLongQueue.java new file mode 100644 index 0000000..7171d55 --- /dev/null +++ b/src/gnu/trove/queue/TLongQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TLongCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TLongQueue extends TLongCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public long element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(long e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public long peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public long poll(); +} diff --git a/src/gnu/trove/queue/TShortQueue.java b/src/gnu/trove/queue/TShortQueue.java new file mode 100644 index 0000000..da65657 --- /dev/null +++ b/src/gnu/trove/queue/TShortQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TShortCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TShortQueue extends TShortCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public short element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(short e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public short peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public short poll(); +} diff --git a/src/gnu/trove/set/TByteSet.java b/src/gnu/trove/set/TByteSet.java new file mode 100644 index 0000000..2f5f0c5 --- /dev/null +++ b/src/gnu/trove/set/TByteSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TByteIterator; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.TByteCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TByteSet extends TByteCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + byte getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an byte value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(byte entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TByteIterator value + */ + @Override + TByteIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + byte[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an byte[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + byte[] toArray(byte[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a byte value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(byte entry); + + /** + * Removes entry from the set. + * + * @param entry + * an byte value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(byte entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TByteCollection + * are present. + * + * @param collection + * a TByteCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TByteCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of byte primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(byte[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TByteCollection to the set. + * + * @param collection + * a TByteCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TByteCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of byte primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(byte[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TByteCollection. + * + * @param collection + * a TByteCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TByteCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of byte primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(byte[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TByteCollection from the set. + * + * @param collection + * a TByteCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TByteCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of byte primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(byte[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TByteProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TCharSet.java b/src/gnu/trove/set/TCharSet.java new file mode 100644 index 0000000..a444222 --- /dev/null +++ b/src/gnu/trove/set/TCharSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TCharIterator; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.TCharCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TCharSet extends TCharCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + char getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an char value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(char entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TCharIterator value + */ + @Override + TCharIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + char[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an char[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + char[] toArray(char[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a char value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(char entry); + + /** + * Removes entry from the set. + * + * @param entry + * an char value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(char entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TCharCollection + * are present. + * + * @param collection + * a TCharCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TCharCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of char primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(char[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TCharCollection to the set. + * + * @param collection + * a TCharCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TCharCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of char primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(char[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TCharCollection. + * + * @param collection + * a TCharCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TCharCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of char primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(char[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TCharCollection from the set. + * + * @param collection + * a TCharCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TCharCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of char primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(char[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TCharProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TDoubleSet.java b/src/gnu/trove/set/TDoubleSet.java new file mode 100644 index 0000000..52f8140 --- /dev/null +++ b/src/gnu/trove/set/TDoubleSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.TDoubleCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TDoubleSet extends TDoubleCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + double getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an double value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(double entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TDoubleIterator value + */ + @Override + TDoubleIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + double[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an double[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + double[] toArray(double[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a double value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(double entry); + + /** + * Removes entry from the set. + * + * @param entry + * an double value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(double entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in + * TDoubleCollection are present. + * + * @param collection + * a TDoubleCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TDoubleCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of double primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(double[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TDoubleCollection to the set. + * + * @param collection + * a TDoubleCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TDoubleCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of double primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(double[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TDoubleCollection. + * + * @param collection + * a TDoubleCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TDoubleCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of double primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(double[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TDoubleCollection from the set. + * + * @param collection + * a TDoubleCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TDoubleCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of double primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(double[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TDoubleProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TFloatSet.java b/src/gnu/trove/set/TFloatSet.java new file mode 100644 index 0000000..862c4f2 --- /dev/null +++ b/src/gnu/trove/set/TFloatSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.TFloatCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TFloatSet extends TFloatCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + float getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an float value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(float entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TFloatIterator value + */ + @Override + TFloatIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + float[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an float[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + float[] toArray(float[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a float value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(float entry); + + /** + * Removes entry from the set. + * + * @param entry + * an float value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(float entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in + * TFloatCollection are present. + * + * @param collection + * a TFloatCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TFloatCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of float primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(float[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TFloatCollection to the set. + * + * @param collection + * a TFloatCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TFloatCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of float primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(float[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TFloatCollection. + * + * @param collection + * a TFloatCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TFloatCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of float primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(float[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TFloatCollection from the set. + * + * @param collection + * a TFloatCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TFloatCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of float primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(float[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TFloatProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TIntSet.java b/src/gnu/trove/set/TIntSet.java new file mode 100644 index 0000000..1589edf --- /dev/null +++ b/src/gnu/trove/set/TIntSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TIntIterator; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.TIntCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TIntSet extends TIntCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + int getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an int value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(int entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TIntIterator value + */ + @Override + TIntIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + int[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an int[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + int[] toArray(int[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a int value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(int entry); + + /** + * Removes entry from the set. + * + * @param entry + * an int value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(int entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TIntCollection + * are present. + * + * @param collection + * a TIntCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TIntCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of int primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(int[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TIntCollection to the set. + * + * @param collection + * a TIntCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TIntCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of int primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(int[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TIntCollection. + * + * @param collection + * a TIntCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TIntCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of int primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(int[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TIntCollection from the set. + * + * @param collection + * a TIntCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TIntCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of int primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(int[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TIntProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TLongSet.java b/src/gnu/trove/set/TLongSet.java new file mode 100644 index 0000000..cd8820e --- /dev/null +++ b/src/gnu/trove/set/TLongSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TLongIterator; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.TLongCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TLongSet extends TLongCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + long getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an long value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(long entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TLongIterator value + */ + @Override + TLongIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + long[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an long[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + long[] toArray(long[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a long value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(long entry); + + /** + * Removes entry from the set. + * + * @param entry + * an long value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(long entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TLongCollection + * are present. + * + * @param collection + * a TLongCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TLongCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of long primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(long[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TLongCollection to the set. + * + * @param collection + * a TLongCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TLongCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of long primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(long[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TLongCollection. + * + * @param collection + * a TLongCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TLongCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of long primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(long[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TLongCollection from the set. + * + * @param collection + * a TLongCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TLongCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of long primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(long[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TLongProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TShortSet.java b/src/gnu/trove/set/TShortSet.java new file mode 100644 index 0000000..fc76362 --- /dev/null +++ b/src/gnu/trove/set/TShortSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TShortIterator; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.TShortCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TShortSet extends TShortCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + short getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an short value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(short entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TShortIterator value + */ + @Override + TShortIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + short[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an short[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + short[] toArray(short[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a short value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(short entry); + + /** + * Removes entry from the set. + * + * @param entry + * an short value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(short entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in + * TShortCollection are present. + * + * @param collection + * a TShortCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TShortCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of short primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(short[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TShortCollection to the set. + * + * @param collection + * a TShortCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TShortCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of short primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(short[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TShortCollection. + * + * @param collection + * a TShortCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TShortCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of short primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(short[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TShortCollection from the set. + * + * @param collection + * a TShortCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TShortCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of short primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(short[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TShortProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/hash/TByteHashSet.java b/src/gnu/trove/set/hash/TByteHashSet.java new file mode 100644 index 0000000..62eadd0 --- /dev/null +++ b/src/gnu/trove/set/hash/TByteHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TByteSet; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TByteCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for byte primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TByteHashSet extends TByteHash implements TByteSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TByteHashSet instance with the default capacity + * and load factor. + */ + public TByteHashSet() { + super(); + } + + /** + * Creates a new TByteHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TByteHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TByteHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a byte value that represents null. + */ + public TByteHashSet(int initial_capacity, float load_factor, byte no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TByteHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TByteHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TByteSet that will be duplicated. + */ + public TByteHashSet(TByteCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TByteHashSet) { + TByteHashSet hashset = (TByteHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TByteHashSet instance containing the elements of + * array. + * + * @param array + * an array of byte primitives + */ + public TByteHashSet(byte[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + byte[] result = new byte[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + byte[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + byte[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(byte val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Byte element : collection) { + byte e = element.byteValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldSet[] = _set; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TByteHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** the collection on which the iterator operates */ + private final TByteHash _hash; + + /** {@inheritDoc} */ + public TByteHashIterator(TByteHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeByte(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readByte(); + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + byte val = in.readByte(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TCharHashSet.java b/src/gnu/trove/set/hash/TCharHashSet.java new file mode 100644 index 0000000..283a9c9 --- /dev/null +++ b/src/gnu/trove/set/hash/TCharHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TCharSet; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TCharCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for char primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TCharHashSet extends TCharHash implements TCharSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TCharHashSet instance with the default capacity + * and load factor. + */ + public TCharHashSet() { + super(); + } + + /** + * Creates a new TCharHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TCharHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TCharHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a char value that represents null. + */ + public TCharHashSet(int initial_capacity, float load_factor, char no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TCharHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TCharHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TCharSet that will be duplicated. + */ + public TCharHashSet(TCharCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TCharHashSet) { + TCharHashSet hashset = (TCharHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TCharHashSet instance containing the elements of + * array. + * + * @param array + * an array of char primitives + */ + public TCharHashSet(char[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + char[] result = new char[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + char[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + char[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(char val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Character element : collection) { + char e = element.charValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldSet[] = _set; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TCharHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** the collection on which the iterator operates */ + private final TCharHash _hash; + + /** {@inheritDoc} */ + public TCharHashIterator(TCharHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeChar(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readChar(); + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + char val = in.readChar(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TCustomHashSet.java b/src/gnu/trove/set/hash/TCustomHashSet.java new file mode 100644 index 0000000..7a285c1 --- /dev/null +++ b/src/gnu/trove/set/hash/TCustomHashSet.java @@ -0,0 +1,411 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.strategy.HashingStrategy; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.array.ToObjectArrayProceedure; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * @author Rob Eden + */ +public class TCustomHashSet extends TCustomObjectHash implements Set, Iterable, Externalizable { + + static final long serialVersionUID = 1L; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TCustomHashSet() { + } + + /** + * Creates a new THashSet instance with the default capacity and + * load factor. + */ + public TCustomHashSet(HashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TCustomHashSet(HashingStrategy strategy, int initialCapacity) { + super(strategy, initialCapacity); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCustomHashSet(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + } + + /** + * Creates a new THashSet instance containing the elements of + * collection. + * + * @param collection + * a Collection value + */ + public TCustomHashSet(HashingStrategy strategy, Collection collection) { + + this(strategy, collection.size()); + addAll(collection); + } + + /** + * Inserts a value into the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the add operation + */ + @Override + public boolean add(E obj) { + int index = insertKey(obj); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + return true; // yes, we added something + } + + @Override + @SuppressWarnings({ "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Set)) { + return false; + } + Set that = (Set) other; + if (that.size() != this.size()) { + return false; + } + return containsAll(that); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(E key) { + h += HashFunctions.hash(key); + return true; + } + } + + /** + * Expands the set to accommodate new values. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + int oldSize = size(); + Object oldSet[] = _set; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + + for (int i = oldCapacity; i-- > 0;) { + E o = (E) oldSet[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { // everyone pays for this because some people can't RTFM + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); + } + } + } + } + + /** + * Returns a new array containing the objects in the set. + * + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] toArray() { + Object[] result = new Object[size()]; + forEach(new ToObjectArrayProceedure(result)); + return result; + } + + /** + * Returns a typed array of the objects in the set. + * + * @param a + * an Object[] value + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); + } + + forEach(new ToObjectArrayProceedure(a)); + + // If this collection fits in the specified array with room to + // spare (i.e., the array has more elements than this + // collection), the element in the array immediately following + // the end of the collection is set to null. This is useful in + // determining the length of this collection only if the + // caller knows that this collection does not contain any null + // elements.) + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + /** Empties the set. */ + @Override + public void clear() { + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + } + + /** + * Removes obj from the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the remove operation. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object obj) { + int index = index(obj); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an Iterator value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public TObjectHashIterator iterator() { + return new TObjectHashIterator(this); + } + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + @SuppressWarnings("ForLoopReplaceableByForEach") + public boolean containsAll(Collection collection) { + for (Iterator i = collection.iterator(); i.hasNext();) { + if (!contains(i.next())) { + return false; + } + } + return true; + } + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + + ensureCapacity(size); + Iterator it = collection.iterator(); + while (size-- > 0) { + if (add(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + Iterator it; + + it = collection.iterator(); + while (size-- > 0) { + if (remove(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + int size = size(); + Iterator it = iterator(); + while (size-- > 0) { + if (!collection.contains(it.next())) { + it.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEach(new TObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(Object value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + E val = (E) in.readObject(); + add(val); + } + } +} diff --git a/src/gnu/trove/set/hash/TDoubleHashSet.java b/src/gnu/trove/set/hash/TDoubleHashSet.java new file mode 100644 index 0000000..ee275fe --- /dev/null +++ b/src/gnu/trove/set/hash/TDoubleHashSet.java @@ -0,0 +1,552 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TDoubleSet; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TDoubleCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for double primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TDoubleHashSet extends TDoubleHash implements TDoubleSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TDoubleHashSet instance with the default capacity + * and load factor. + */ + public TDoubleHashSet() { + super(); + } + + /** + * Creates a new TDoubleHashSet instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TDoubleHashSet instance with a prime capacity + * equal to or greater than initial_capacity and with the specified + * load factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a double value that represents null. + */ + public TDoubleHashSet(int initial_capacity, float load_factor, double no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TDoubleHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TDoubleHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TDoubleSet that will be duplicated. + */ + public TDoubleHashSet(TDoubleCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TDoubleHashSet) { + TDoubleHashSet hashset = (TDoubleHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TDoubleHashSet instance containing the elements of + * array. + * + * @param array + * an array of double primitives + */ + public TDoubleHashSet(double[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + double[] result = new double[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + double[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + double[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(double val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Double element : collection) { + double e = element.doubleValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldSet[] = _set; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TDoubleHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** the collection on which the iterator operates */ + private final TDoubleHash _hash; + + /** {@inheritDoc} */ + public TDoubleHashIterator(TDoubleHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeDouble(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readDouble(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + double val = in.readDouble(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TFloatHashSet.java b/src/gnu/trove/set/hash/TFloatHashSet.java new file mode 100644 index 0000000..fe75fa0 --- /dev/null +++ b/src/gnu/trove/set/hash/TFloatHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TFloatSet; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TFloatCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for float primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TFloatHashSet extends TFloatHash implements TFloatSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TFloatHashSet instance with the default capacity + * and load factor. + */ + public TFloatHashSet() { + super(); + } + + /** + * Creates a new TFloatHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TFloatHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TFloatHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a float value that represents null. + */ + public TFloatHashSet(int initial_capacity, float load_factor, float no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TFloatHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TFloatHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TFloatSet that will be duplicated. + */ + public TFloatHashSet(TFloatCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TFloatHashSet) { + TFloatHashSet hashset = (TFloatHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TFloatHashSet instance containing the elements of + * array. + * + * @param array + * an array of float primitives + */ + public TFloatHashSet(float[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + float[] result = new float[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + float[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + float[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(float val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Float element : collection) { + float e = element.floatValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldSet[] = _set; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TFloatHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** the collection on which the iterator operates */ + private final TFloatHash _hash; + + /** {@inheritDoc} */ + public TFloatHashIterator(TFloatHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeFloat(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readFloat(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + float val = in.readFloat(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/THashSet.java b/src/gnu/trove/set/hash/THashSet.java new file mode 100644 index 0000000..47ee23a --- /dev/null +++ b/src/gnu/trove/set/hash/THashSet.java @@ -0,0 +1,418 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.impl.HashFunctions; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.array.ToObjectArrayProceedure; +import gnu.trove.iterator.hash.TObjectHashIterator; + +import java.io.*; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; +import java.util.Arrays; +import java.lang.reflect.Array; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: THashSet.java,v 1.1.2.8 2010/03/02 04:09:50 robeden Exp $ + */ + +public class THashSet extends TObjectHash implements Set, Iterable, Externalizable { + + static final long serialVersionUID = 1L; + + /** + * Creates a new THashSet instance with the default capacity and + * load factor. + */ + public THashSet() { + super(); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public THashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public THashSet(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new THashSet instance containing the elements of + * collection. + * + * @param collection + * a Collection value + */ + public THashSet(Collection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Inserts a value into the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the add operation + */ + @Override + public boolean add(E obj) { + int index = insertKey(obj); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + return true; // yes, we added something + } + + @Override + @SuppressWarnings({ "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Set)) { + return false; + } + Set that = (Set) other; + if (that.size() != this.size()) { + return false; + } + return containsAll(that); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(E key) { + h += HashFunctions.hash(key); + return true; + } + } + + /** + * Expands the set to accommodate new values. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldSize = size(); + Object oldSet[] = _set; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + + int count = 0; + for (int i = oldCapacity; i-- > 0;) { + E o = (E) oldSet[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { // everyone pays for this because some people can't RTFM + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); + } + // + count++; + } + } + // Last check: size before and after should be the same + reportPotentialConcurrentMod(size(), oldSize); + } + + /** + * Returns a new array containing the objects in the set. + * + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] toArray() { + Object[] result = new Object[size()]; + forEach(new ToObjectArrayProceedure(result)); + return result; + } + + /** + * Returns a typed array of the objects in the set. + * + * @param a + * an Object[] value + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); + } + + forEach(new ToObjectArrayProceedure(a)); + + // If this collection fits in the specified array with room to + // spare (i.e., the array has more elements than this + // collection), the element in the array immediately following + // the end of the collection is set to null. This is useful in + // determining the length of this collection only if the + // caller knows that this collection does not contain any null + // elements.) + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + /** + * Empties the set. + */ + @Override + public void clear() { + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + } + + /** + * Removes obj from the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the remove operation. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object obj) { + int index = index(obj); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an Iterator value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public TObjectHashIterator iterator() { + return new TObjectHashIterator(this); + } + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + @SuppressWarnings("ForLoopReplaceableByForEach") + public boolean containsAll(Collection collection) { + for (Iterator i = collection.iterator(); i.hasNext();) { + if (!contains(i.next())) { + return false; + } + } + return true; + } + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + + ensureCapacity(size); + Iterator it = collection.iterator(); + while (size-- > 0) { + if (add(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + Iterator it; + + it = collection.iterator(); + while (size-- > 0) { + if (remove(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + int size = size(); + Iterator it = iterator(); + while (size-- > 0) { + if (!collection.contains(it.next())) { + it.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEach(new TObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(Object value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + writeEntries(out); + } + + protected void writeEntries(ObjectOutput out) throws IOException { + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + E val = (E) in.readObject(); + add(val); + } + + } +} // THashSet diff --git a/src/gnu/trove/set/hash/TIntHashSet.java b/src/gnu/trove/set/hash/TIntHashSet.java new file mode 100644 index 0000000..2069feb --- /dev/null +++ b/src/gnu/trove/set/hash/TIntHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TIntSet; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TIntCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for int primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TIntHashSet extends TIntHash implements TIntSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TIntHashSet instance with the default capacity and + * load factor. + */ + public TIntHashSet() { + super(); + } + + /** + * Creates a new TIntHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TIntHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TIntHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a int value that represents null. + */ + public TIntHashSet(int initial_capacity, float load_factor, int no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TIntHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TIntHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TIntSet that will be duplicated. + */ + public TIntHashSet(TIntCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TIntHashSet) { + TIntHashSet hashset = (TIntHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TIntHashSet instance containing the elements of + * array. + * + * @param array + * an array of int primitives + */ + public TIntHashSet(int[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + int[] result = new int[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + int[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + int[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(int val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Integer element : collection) { + int e = element.intValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldSet[] = _set; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TIntHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** the collection on which the iterator operates */ + private final TIntHash _hash; + + /** {@inheritDoc} */ + public TIntHashIterator(TIntHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeInt(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readInt(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + int val = in.readInt(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TLinkedHashSet.java b/src/gnu/trove/set/hash/TLinkedHashSet.java new file mode 100644 index 0000000..0dd9bd2 --- /dev/null +++ b/src/gnu/trove/set/hash/TLinkedHashSet.java @@ -0,0 +1,320 @@ +package gnu.trove.set.hash; + +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.list.TIntList; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.list.linked.TIntLinkedList; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectProcedure; + +import java.io.IOException; +import java.io.ObjectOutput; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; + +/** + * Created by IntelliJ IDEA. User: Johan Date: 15/03/11 Time: 18:15 To change + * this template use File | Settings | File Templates. + */ +public class TLinkedHashSet extends THashSet { + TIntList order; + + /** + * Creates a new THashSet instance with the default capacity and + * load factor. + */ + public TLinkedHashSet() { + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TLinkedHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLinkedHashSet(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new THashSet instance containing the elements of + * collection. + * + * @param es + * a Collection value + */ + public TLinkedHashSet(Collection es) { + super(es); + } + + /** + * initializes the Object set of this hash table. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + order = new TIntArrayList(initialCapacity) { + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_set.length, capacity); + int[] tmp = new int[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + }; + return super.setUp(initialCapacity); // To change body of overridden methods use File | Settings | File + // Templates. + } + + /** + * Empties the set. + */ + @Override + public void clear() { + super.clear(); + order.clear(); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + + for (Iterator it = iterator(); it.hasNext();) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(it.next()); + } + + buf.append("}"); + return buf.toString(); + } + + /** + * Inserts a value into the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the add operation + */ + @Override + public boolean add(E obj) { + int index = insertKey(obj); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + if (!order.add(index)) + throw new IllegalStateException("Order not changed after insert"); + + postInsertHook(consumeFreeSlot); + return true; // yes, we added something + } + + @Override + protected void removeAt(int index) { + // Remove from order first since super.removeAt can trigger compaction + // making the index invalid afterwards + order.remove(index); + super.removeAt(index); + } + + /** + * Expands the set to accommodate new values. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + TIntLinkedList oldOrder = new TIntLinkedList(order); + int oldSize = size(); + + Object oldSet[] = _set; + + order.clear(); + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + + for (TIntIterator iterator = oldOrder.iterator(); iterator.hasNext();) { + int i = iterator.next(); + E o = (E) oldSet[i]; + if (o == FREE || o == REMOVED) { + throw new IllegalStateException("Iterating over empty location while rehashing"); + } + + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { // everyone pays for this because some people can't RTFM + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); + } + + if (!order.add(index)) + throw new IllegalStateException("Order not changed after insert"); + } + } + + } + + class WriteProcedure implements TIntProcedure { + final ObjectOutput output; + IOException ioException; + + WriteProcedure(ObjectOutput output) { + this.output = output; + } + + public IOException getIoException() { + return ioException; + } + + @Override + public boolean execute(int value) { + try { + output.writeObject(_set[value]); + } catch (IOException e) { + ioException = e; + return false; + } + return true; + } + + } + + @Override + protected void writeEntries(ObjectOutput out) throws IOException { + // ENTRIES + WriteProcedure writeProcedure = new WriteProcedure(out); + if (!order.forEach(writeProcedure)) + throw writeProcedure.getIoException(); + } + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an Iterator value + */ + @Override + public TObjectHashIterator iterator() { + return new TObjectHashIterator(this) { + TIntIterator localIterator = order.iterator(); + int lastIndex; + + /** + * Moves the iterator to the next Object and returns it. + * + * @return an Object value + * @throws java.util.ConcurrentModificationException + * if the structure was changed using a method that isn't on this + * iterator. + * @throws java.util.NoSuchElementException + * if this is called on an exhausted iterator. + */ + @Override + public E next() { + lastIndex = localIterator.next(); + return objectAtIndex(lastIndex); + } + + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext() { + return localIterator.hasNext(); // To change body of overridden methods use File | Settings | File + // Templates. + } + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove() { + // Remove for iterator first + localIterator.remove(); + // the removal within removeAt() will not change the collection + // but the localIterator will remain valid + try { + _hash.tempDisableAutoCompaction(); + TLinkedHashSet.this.removeAt(lastIndex); + } finally { + _hash.reenableAutoCompaction(false); + } + } + }; // To change body of overridden methods use File | Settings | File Templates. + } + + class ForEachProcedure implements TIntProcedure { + boolean changed = false; + final Object[] set; + final TObjectProcedure procedure; + + public ForEachProcedure(Object[] set, TObjectProcedure procedure) { + this.set = set; + this.procedure = procedure; + } + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(int value) { + return procedure.execute((E) set[value]); + } + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEach(TObjectProcedure procedure) { + ForEachProcedure forEachProcedure = new ForEachProcedure(_set, procedure); + return order.forEach(forEachProcedure); + } +} diff --git a/src/gnu/trove/set/hash/TLongHashSet.java b/src/gnu/trove/set/hash/TLongHashSet.java new file mode 100644 index 0000000..64dfbd5 --- /dev/null +++ b/src/gnu/trove/set/hash/TLongHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TLongSet; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TLongCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for long primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TLongHashSet extends TLongHash implements TLongSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TLongHashSet instance with the default capacity + * and load factor. + */ + public TLongHashSet() { + super(); + } + + /** + * Creates a new TLongHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TLongHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TLongHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a long value that represents null. + */ + public TLongHashSet(int initial_capacity, float load_factor, long no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TLongHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TLongHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TLongSet that will be duplicated. + */ + public TLongHashSet(TLongCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TLongHashSet) { + TLongHashSet hashset = (TLongHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TLongHashSet instance containing the elements of + * array. + * + * @param array + * an array of long primitives + */ + public TLongHashSet(long[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + long[] result = new long[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + long[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + long[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(long val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Long element : collection) { + long e = element.longValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldSet[] = _set; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TLongHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** the collection on which the iterator operates */ + private final TLongHash _hash; + + /** {@inheritDoc} */ + public TLongHashIterator(TLongHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeLong(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readLong(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + long val = in.readLong(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TShortHashSet.java b/src/gnu/trove/set/hash/TShortHashSet.java new file mode 100644 index 0000000..b8e8b0c --- /dev/null +++ b/src/gnu/trove/set/hash/TShortHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TShortSet; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TShortCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for short primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TShortHashSet extends TShortHash implements TShortSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TShortHashSet instance with the default capacity + * and load factor. + */ + public TShortHashSet() { + super(); + } + + /** + * Creates a new TShortHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TShortHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TShortHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a short value that represents null. + */ + public TShortHashSet(int initial_capacity, float load_factor, short no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TShortHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TShortHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TShortSet that will be duplicated. + */ + public TShortHashSet(TShortCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TShortHashSet) { + TShortHashSet hashset = (TShortHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TShortHashSet instance containing the elements of + * array. + * + * @param array + * an array of short primitives + */ + public TShortHashSet(short[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + short[] result = new short[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + short[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + short[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(short val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Short element : collection) { + short e = element.shortValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldSet[] = _set; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TShortHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** the collection on which the iterator operates */ + private final TShortHash _hash; + + /** {@inheritDoc} */ + public TShortHashIterator(TShortHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeShort(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readShort(); + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + short val = in.readShort(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/stack/TByteStack.java b/src/gnu/trove/stack/TByteStack.java new file mode 100644 index 0000000..a8530c0 --- /dev/null +++ b/src/gnu/trove/stack/TByteStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of byte primitives. + */ +public interface TByteStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an byte value + */ + public void push(byte val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an byte value + */ + public byte pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an byte value + */ + public byte peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an byte[] value + */ + public byte[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(byte[] dest); +} diff --git a/src/gnu/trove/stack/TCharStack.java b/src/gnu/trove/stack/TCharStack.java new file mode 100644 index 0000000..0a345a6 --- /dev/null +++ b/src/gnu/trove/stack/TCharStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of char primitives. + */ +public interface TCharStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an char value + */ + public void push(char val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an char value + */ + public char pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an char value + */ + public char peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an char[] value + */ + public char[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(char[] dest); +} diff --git a/src/gnu/trove/stack/TDoubleStack.java b/src/gnu/trove/stack/TDoubleStack.java new file mode 100644 index 0000000..e685497 --- /dev/null +++ b/src/gnu/trove/stack/TDoubleStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of double primitives. + */ +public interface TDoubleStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an double value + */ + public void push(double val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an double value + */ + public double pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an double value + */ + public double peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an double[] value + */ + public double[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(double[] dest); +} diff --git a/src/gnu/trove/stack/TFloatStack.java b/src/gnu/trove/stack/TFloatStack.java new file mode 100644 index 0000000..3955759 --- /dev/null +++ b/src/gnu/trove/stack/TFloatStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of float primitives. + */ +public interface TFloatStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an float value + */ + public void push(float val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an float value + */ + public float pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an float value + */ + public float peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an float[] value + */ + public float[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(float[] dest); +} diff --git a/src/gnu/trove/stack/TIntStack.java b/src/gnu/trove/stack/TIntStack.java new file mode 100644 index 0000000..61a3674 --- /dev/null +++ b/src/gnu/trove/stack/TIntStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of int primitives. + */ +public interface TIntStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an int value + */ + public void push(int val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an int value + */ + public int pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an int value + */ + public int peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an int[] value + */ + public int[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(int[] dest); +} diff --git a/src/gnu/trove/stack/TLongStack.java b/src/gnu/trove/stack/TLongStack.java new file mode 100644 index 0000000..e2053a3 --- /dev/null +++ b/src/gnu/trove/stack/TLongStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of long primitives. + */ +public interface TLongStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an long value + */ + public void push(long val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an long value + */ + public long pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an long value + */ + public long peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an long[] value + */ + public long[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(long[] dest); +} diff --git a/src/gnu/trove/stack/TShortStack.java b/src/gnu/trove/stack/TShortStack.java new file mode 100644 index 0000000..3e62249 --- /dev/null +++ b/src/gnu/trove/stack/TShortStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of short primitives. + */ +public interface TShortStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an short value + */ + public void push(short val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an short value + */ + public short pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an short value + */ + public short peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an short[] value + */ + public short[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(short[] dest); +} diff --git a/src/gnu/trove/stack/array/TByteArrayStack.java b/src/gnu/trove/stack/array/TByteArrayStack.java new file mode 100644 index 0000000..28249f8 --- /dev/null +++ b/src/gnu/trove/stack/array/TByteArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TByteStack; +import gnu.trove.list.array.TByteArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of byte primitives, backed by a TByteArrayList + */ +public class TByteArrayStack implements TByteStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TByteArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TByteArrayStack instance with the default + * capacity. + */ + public TByteArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TByteArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TByteArrayStack(int capacity) { + _list = new TByteArrayList(capacity); + } + + /** + * Creates a new TByteArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TByteArrayStack(int capacity, byte no_entry_value) { + _list = new TByteArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TByteArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TByteArrayStack(TByteStack stack) { + if (stack instanceof TByteArrayStack) { + TByteArrayStack array_stack = (TByteArrayStack) stack; + this._list = new TByteArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TByteArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public byte getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an byte value + */ + @Override + public void push(byte val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an byte value + */ + @Override + public byte pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an byte value + */ + @Override + public byte peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an byte[] value + */ + @Override + public byte[] toArray() { + byte[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(byte[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(byte[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(byte[] dest, int i, int j) { + byte tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TByteArrayStack that = (TByteArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TByteArrayList) in.readObject(); + } +} // TByteArrayStack diff --git a/src/gnu/trove/stack/array/TCharArrayStack.java b/src/gnu/trove/stack/array/TCharArrayStack.java new file mode 100644 index 0000000..57e9a20 --- /dev/null +++ b/src/gnu/trove/stack/array/TCharArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TCharStack; +import gnu.trove.list.array.TCharArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of char primitives, backed by a TCharArrayList + */ +public class TCharArrayStack implements TCharStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TCharArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TCharArrayStack instance with the default + * capacity. + */ + public TCharArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TCharArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TCharArrayStack(int capacity) { + _list = new TCharArrayList(capacity); + } + + /** + * Creates a new TCharArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TCharArrayStack(int capacity, char no_entry_value) { + _list = new TCharArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TCharArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TCharArrayStack(TCharStack stack) { + if (stack instanceof TCharArrayStack) { + TCharArrayStack array_stack = (TCharArrayStack) stack; + this._list = new TCharArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TCharArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public char getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an char value + */ + @Override + public void push(char val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an char value + */ + @Override + public char pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an char value + */ + @Override + public char peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an char[] value + */ + @Override + public char[] toArray() { + char[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(char[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(char[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(char[] dest, int i, int j) { + char tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TCharArrayStack that = (TCharArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TCharArrayList) in.readObject(); + } +} // TCharArrayStack diff --git a/src/gnu/trove/stack/array/TDoubleArrayStack.java b/src/gnu/trove/stack/array/TDoubleArrayStack.java new file mode 100644 index 0000000..0a89b03 --- /dev/null +++ b/src/gnu/trove/stack/array/TDoubleArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TDoubleStack; +import gnu.trove.list.array.TDoubleArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of double primitives, backed by a TDoubleArrayList + */ +public class TDoubleArrayStack implements TDoubleStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TDoubleArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TDoubleArrayStack instance with the default + * capacity. + */ + public TDoubleArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TDoubleArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TDoubleArrayStack(int capacity) { + _list = new TDoubleArrayList(capacity); + } + + /** + * Creates a new TDoubleArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TDoubleArrayStack(int capacity, double no_entry_value) { + _list = new TDoubleArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TDoubleArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TDoubleArrayStack(TDoubleStack stack) { + if (stack instanceof TDoubleArrayStack) { + TDoubleArrayStack array_stack = (TDoubleArrayStack) stack; + this._list = new TDoubleArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TDoubleArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public double getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an double value + */ + @Override + public void push(double val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an double value + */ + @Override + public double pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an double value + */ + @Override + public double peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an double[] value + */ + @Override + public double[] toArray() { + double[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(double[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(double[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(double[] dest, int i, int j) { + double tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TDoubleArrayStack that = (TDoubleArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TDoubleArrayList) in.readObject(); + } +} // TDoubleArrayStack diff --git a/src/gnu/trove/stack/array/TFloatArrayStack.java b/src/gnu/trove/stack/array/TFloatArrayStack.java new file mode 100644 index 0000000..67fefef --- /dev/null +++ b/src/gnu/trove/stack/array/TFloatArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TFloatStack; +import gnu.trove.list.array.TFloatArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of float primitives, backed by a TFloatArrayList + */ +public class TFloatArrayStack implements TFloatStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TFloatArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TFloatArrayStack instance with the default + * capacity. + */ + public TFloatArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TFloatArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TFloatArrayStack(int capacity) { + _list = new TFloatArrayList(capacity); + } + + /** + * Creates a new TFloatArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TFloatArrayStack(int capacity, float no_entry_value) { + _list = new TFloatArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TFloatArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TFloatArrayStack(TFloatStack stack) { + if (stack instanceof TFloatArrayStack) { + TFloatArrayStack array_stack = (TFloatArrayStack) stack; + this._list = new TFloatArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TFloatArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public float getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an float value + */ + @Override + public void push(float val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an float value + */ + @Override + public float pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an float value + */ + @Override + public float peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an float[] value + */ + @Override + public float[] toArray() { + float[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(float[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(float[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(float[] dest, int i, int j) { + float tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TFloatArrayStack that = (TFloatArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TFloatArrayList) in.readObject(); + } +} // TFloatArrayStack diff --git a/src/gnu/trove/stack/array/TIntArrayStack.java b/src/gnu/trove/stack/array/TIntArrayStack.java new file mode 100644 index 0000000..0ad6232 --- /dev/null +++ b/src/gnu/trove/stack/array/TIntArrayStack.java @@ -0,0 +1,287 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TIntStack; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of int primitives, backed by a TIntArrayList + */ +public class TIntArrayStack implements TIntStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TIntArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TIntArrayStack instance with the default capacity. + */ + public TIntArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TIntArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TIntArrayStack(int capacity) { + _list = new TIntArrayList(capacity); + } + + /** + * Creates a new TIntArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TIntArrayStack(int capacity, int no_entry_value) { + _list = new TIntArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TIntArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TIntArrayStack(TIntStack stack) { + if (stack instanceof TIntArrayStack) { + TIntArrayStack array_stack = (TIntArrayStack) stack; + this._list = new TIntArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TIntArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public int getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an int value + */ + @Override + public void push(int val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an int value + */ + @Override + public int pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an int value + */ + @Override + public int peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an int[] value + */ + @Override + public int[] toArray() { + int[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(int[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(int[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int[] dest, int i, int j) { + int tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TIntArrayStack that = (TIntArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TIntArrayList) in.readObject(); + } +} // TIntArrayStack diff --git a/src/gnu/trove/stack/array/TLongArrayStack.java b/src/gnu/trove/stack/array/TLongArrayStack.java new file mode 100644 index 0000000..7c0743c --- /dev/null +++ b/src/gnu/trove/stack/array/TLongArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TLongStack; +import gnu.trove.list.array.TLongArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of long primitives, backed by a TLongArrayList + */ +public class TLongArrayStack implements TLongStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TLongArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TLongArrayStack instance with the default + * capacity. + */ + public TLongArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TLongArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TLongArrayStack(int capacity) { + _list = new TLongArrayList(capacity); + } + + /** + * Creates a new TLongArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TLongArrayStack(int capacity, long no_entry_value) { + _list = new TLongArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TLongArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TLongArrayStack(TLongStack stack) { + if (stack instanceof TLongArrayStack) { + TLongArrayStack array_stack = (TLongArrayStack) stack; + this._list = new TLongArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TLongArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public long getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an long value + */ + @Override + public void push(long val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an long value + */ + @Override + public long pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an long value + */ + @Override + public long peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an long[] value + */ + @Override + public long[] toArray() { + long[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(long[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(long[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(long[] dest, int i, int j) { + long tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TLongArrayStack that = (TLongArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TLongArrayList) in.readObject(); + } +} // TLongArrayStack diff --git a/src/gnu/trove/stack/array/TShortArrayStack.java b/src/gnu/trove/stack/array/TShortArrayStack.java new file mode 100644 index 0000000..4259e7d --- /dev/null +++ b/src/gnu/trove/stack/array/TShortArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TShortStack; +import gnu.trove.list.array.TShortArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of short primitives, backed by a TShortArrayList + */ +public class TShortArrayStack implements TShortStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TShortArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TShortArrayStack instance with the default + * capacity. + */ + public TShortArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TShortArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TShortArrayStack(int capacity) { + _list = new TShortArrayList(capacity); + } + + /** + * Creates a new TShortArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TShortArrayStack(int capacity, short no_entry_value) { + _list = new TShortArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TShortArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TShortArrayStack(TShortStack stack) { + if (stack instanceof TShortArrayStack) { + TShortArrayStack array_stack = (TShortArrayStack) stack; + this._list = new TShortArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TShortArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public short getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an short value + */ + @Override + public void push(short val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an short value + */ + @Override + public short pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an short value + */ + @Override + public short peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an short[] value + */ + @Override + public short[] toArray() { + short[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(short[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(short[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(short[] dest, int i, int j) { + short tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TShortArrayStack that = (TShortArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TShortArrayList) in.readObject(); + } +} // TShortArrayStack diff --git a/src/gnu/trove/strategy/HashingStrategy.java b/src/gnu/trove/strategy/HashingStrategy.java new file mode 100644 index 0000000..3ba3458 --- /dev/null +++ b/src/gnu/trove/strategy/HashingStrategy.java @@ -0,0 +1,59 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.strategy; + +import java.io.Serializable; + +/** + * Interface to support pluggable hashing strategies in maps and sets. + * Implementers can use this interface to make the trove hashing algorithms use + * object values, values provided by the java runtime, or a custom strategy when + * computing hashcodes. + * + * @author Eric Friedman + * @author Rob Eden + */ + +public interface HashingStrategy extends Serializable { + static final long serialVersionUID = 5674097166776615540L; + + /** + * Computes a hash code for the specified object. Implementers can use the + * object's own hashCode method, the Java runtime's + * identityHashCode, or a custom scheme. + * + * @param object + * for which the hashcode is to be computed + * @return the hashCode + */ + int computeHashCode(T object); + + /** + * Compares o1 and o2 for equality. Strategy implementers may use the objects' + * own equals() methods, compare object references, or implement some custom + * scheme. + * + * @param o1 + * an Object value + * @param o2 + * an Object value + * @return true if the objects are equal according to this strategy. + */ + boolean equals(T o1, T o2); +} diff --git a/src/gnu/trove/strategy/IdentityHashingStrategy.java b/src/gnu/trove/strategy/IdentityHashingStrategy.java new file mode 100644 index 0000000..9b6baf4 --- /dev/null +++ b/src/gnu/trove/strategy/IdentityHashingStrategy.java @@ -0,0 +1,26 @@ +package gnu.trove.strategy; + +/** + * A {@link gnu.trove.strategy.HashingStrategy} that does identity comparisons + * (==) and uses {@link System#identityHashCode(Object)} for hashCode + * generation. + */ +public class IdentityHashingStrategy implements HashingStrategy { + static final long serialVersionUID = -5188534454583764904L; + + /** + * A single instance that can be shared with multiple collections. This instance + * is thread safe. + */ + public static final IdentityHashingStrategy INSTANCE = new IdentityHashingStrategy(); + + @Override + public int computeHashCode(K object) { + return System.identityHashCode(object); + } + + @Override + public boolean equals(K o1, K o2) { + return o1 == o2; + } +} diff --git a/src/me/Utils.java b/src/me/Utils.java new file mode 100644 index 0000000..9c250a7 --- /dev/null +++ b/src/me/Utils.java @@ -0,0 +1,70 @@ +package me; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import ru.tehkode.permissions.bukkit.PermissionsEx; + +public class Utils { + public static String c(String text) { + return ChatColor.translateAlternateColorCodes('&', text); + } + + public static void broadcast(String message) { + for (Player p : Bukkit.getOnlinePlayers()) { + p.sendMessage(Utils.c(message)); + } + } + + + + public String getTabRank(Player p) { + final String prefix = PermissionsEx.getUser(p).getGroups()[0].getPrefix().replace("[", "").replace("]", ""); + final String rank = PermissionsEx.getUser(p).getGroups()[0].getName(); + if (prefix.equals("&4")) { + return Utils.c("&4" + rank); + } else if (prefix.equals("&c")) { + return Utils.c("&c" + rank); + } else if (prefix.equals("&6")) { + return Utils.c("&6" + rank); + } else if (prefix.equals("&e")) { + return Utils.c("&e" + rank); + } else if (prefix.equals("&2")) { + return Utils.c("&2" + rank); + } else if (prefix.equals("&a")) { + return Utils.c("&a" + rank); + } else if (prefix.equals("&b")) { + return Utils.c("&b" + rank); + } else if (prefix.equals("&3")) { + return Utils.c("&3" + rank); + } else if (prefix.equals("&1")) { + return Utils.c("&1" + rank); + } else if (prefix.equals("&9")) { + return Utils.c("&9" + rank); + } else if (prefix.equals("&d")) { + return Utils.c("&d" + rank); + } else if (prefix.equals("&5")) { + return Utils.c("&5" + rank); + } else if (prefix.equals("&f")) { + return Utils.c("&f" + rank); + } else if (prefix.equals("&7")) { + return Utils.c("&7" + rank); + } else if (prefix.equals("&8")) { + return Utils.c("&8" + rank); + } else if (prefix.equals("&0")) { + return Utils.c("&0" + rank); + } else if (prefix.equals(null)) { + return rank; + } else if (prefix.equals("")) { + return rank; + } else if (prefix.equals(" ")) { + return rank; + } else { + return prefix; + } + + } + + +} diff --git a/src/me/bruce/factions/KIts/GiveBook.java b/src/me/bruce/factions/KIts/GiveBook.java new file mode 100644 index 0000000..dea7566 --- /dev/null +++ b/src/me/bruce/factions/KIts/GiveBook.java @@ -0,0 +1,33 @@ +package me.bruce.factions.KIts; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import net.md_5.bungee.api.ChatColor; + +public class GiveBook { + + + public static void GiveBooktoplayer(Player p) { + ItemStack book = new ItemStack(Material.BOOK); + ItemMeta bmeta = book.getItemMeta(); + bmeta.setDisplayName(ChatColor.GOLD + "Select a kit"); + book.setItemMeta(bmeta); + + p.getInventory().addItem(book); + } + public static void takeBooktoplayer(Player p) { + ItemStack book = new ItemStack(Material.BOOK); + ItemMeta bmeta = book.getItemMeta(); + bmeta.setDisplayName(ChatColor.GOLD + "Select a kit"); + book.setItemMeta(bmeta); + + p.getInventory().remove(book);; + } + + + + +} diff --git a/src/me/bruce/factions/KIts/KitsBook.java b/src/me/bruce/factions/KIts/KitsBook.java new file mode 100644 index 0000000..170cb5a --- /dev/null +++ b/src/me/bruce/factions/KIts/KitsBook.java @@ -0,0 +1,73 @@ +package me.bruce.factions.KIts; + +import java.util.ArrayList; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import net.md_5.bungee.api.ChatColor; + +public class KitsBook { + + public static void BookGui(Player p) { + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + ArrayList lore3 = new ArrayList(); + + Inventory book = Bukkit.createInventory(null, 9, ChatColor.GOLD + ChatColor.BOLD.toString() + "Kits Selector"); + + //Diamond Kit + ItemStack diamond = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemMeta dmeta = diamond.getItemMeta(); + dmeta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Diamond Kit §7(Right Click)"); + lore.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Diamond Kit&7.")); + lore.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + dmeta.setLore(lore); + diamond.setItemMeta(dmeta); + + //Bard + ItemStack Bard = new ItemStack(Material.GOLD_CHESTPLATE); + ItemMeta bmeta = Bard.getItemMeta(); + bmeta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Bard Kit §7(Right Click)"); + lore1.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore1.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Bard Kit&7.")); + lore1.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + bmeta.setLore(lore1); + Bard.setItemMeta(bmeta); + + //Archer Kit + ItemStack Archer = new ItemStack(Material.LEATHER_CHESTPLATE); + ItemMeta ameta = Archer.getItemMeta(); + ameta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Archer Kit §7(Right Click)"); + lore2.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore2.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Archer Kit&7.")); + lore2.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + ameta.setLore(lore2); + Archer.setItemMeta(ameta); + + //Builder Kit + ItemStack Builder = new ItemStack(Material.IRON_CHESTPLATE); + ItemMeta bumeta = Builder.getItemMeta(); + bumeta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Builder Kit §7(Right Click)"); + lore3.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore3.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Builder Kit&7.")); + lore3.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + bumeta.setLore(lore3); + Builder.setItemMeta(bumeta); + + book.setItem(0, diamond); + book.setItem(1, Bard); + book.setItem(2, Archer); + book.setItem(3, Builder); + + p.openInventory(book); + + } + +} diff --git a/src/me/bruce/factions/KIts/KitsInteract.java b/src/me/bruce/factions/KIts/KitsInteract.java new file mode 100644 index 0000000..a4c16bd --- /dev/null +++ b/src/me/bruce/factions/KIts/KitsInteract.java @@ -0,0 +1,37 @@ +package me.bruce.factions.KIts; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import net.md_5.bungee.api.ChatColor; + +public class KitsInteract implements Listener { + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + Player p = e.getPlayer(); + ItemStack item = e.getItem(); + Action action = e.getAction(); + if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { + if (item == null) return; + if (item.getType() == Material.AIR) return; + + + if (item.getType() == Material.BOOK) { + if (!item.hasItemMeta()) return; + + if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "Select a kit")) { + KitsBook.BookGui(p); + e.setCancelled(true); + } + } + } + } + + +} diff --git a/src/me/bruce/factions/KIts/KitsInvClick.java b/src/me/bruce/factions/KIts/KitsInvClick.java new file mode 100644 index 0000000..6313dbe --- /dev/null +++ b/src/me/bruce/factions/KIts/KitsInvClick.java @@ -0,0 +1,55 @@ +package me.bruce.factions.KIts; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.KIts.Kitsgive.GiveKits; +import me.bruce.factions.prefix.inventory.PrefixInventoryClick; +import ru.tehkode.permissions.PermissionUser; +import ru.tehkode.permissions.bukkit.PermissionsEx; + +public class KitsInvClick implements Listener { + + + @EventHandler + public void onInvClick(final InventoryClickEvent event) { + final Player player = (Player)event.getWhoClicked(); + if (event.getInventory().getName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Kits Selector")) { + event.setCancelled(true); + if (event.getCurrentItem() == null) { + return; + } + if (event.getCurrentItem().getType().equals((Object)Material.DIAMOND_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Diamond Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setDiamond(player); + player.closeInventory(); + + } + if (event.getCurrentItem().getType().equals((Object)Material.GOLD_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Bard Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setBard(player); + player.closeInventory(); + + } + if (event.getCurrentItem().getType().equals((Object)Material.LEATHER_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Archer Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setArcher(player); + player.closeInventory(); + + } + if (event.getCurrentItem().getType().equals((Object)Material.IRON_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Builder Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setBuilder(player); + player.closeInventory(); + + } + } + } +} + + diff --git a/src/me/bruce/factions/KIts/Kitsgive/GiveKits.java b/src/me/bruce/factions/KIts/Kitsgive/GiveKits.java new file mode 100644 index 0000000..48cb343 --- /dev/null +++ b/src/me/bruce/factions/KIts/Kitsgive/GiveKits.java @@ -0,0 +1,187 @@ +package me.bruce.factions.KIts.Kitsgive; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class GiveKits { + + private static final ItemStack SPLASH_HEATH = new ItemStack(Material.POTION, 1, (short)16421); + + + //Kit stuff + private static int maxProtection = 1; + private static int maxSharpness = 1; + private static int maxUnbreaking = 3; + private static int maxFF = 4; + private static int maxPower = 3; + private static int maxFire = 0; + private static int maxInfinite = 1; + + public static void setDiamond(Player player) { + ItemStack helm = new ItemStack(Material.DIAMOND_HELMET); + ItemStack chest = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemStack pants = new ItemStack(Material.DIAMOND_LEGGINGS); + ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + player.getInventory().addItem(sword, new ItemStack(Material.ENDER_PEARL, 16), new ItemStack(Material.COOKED_BEEF, 32)); + player.getInventory().setItem(8, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setItem(17, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setItem(26, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setItem(35, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + public static void setBard(Player player) { + ItemStack helm = new ItemStack(Material.GOLD_HELMET); + ItemStack chest = new ItemStack(Material.GOLD_CHESTPLATE); + ItemStack pants = new ItemStack(Material.GOLD_LEGGINGS); + ItemStack boots = new ItemStack(Material.GOLD_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + player.getInventory().addItem(sword, new ItemStack(Material.ENDER_PEARL, 16), new ItemStack(Material.COOKED_BEEF, 32), new ItemStack(Material.BLAZE_POWDER, 32), new ItemStack(Material.SUGAR, 32), new ItemStack(Material.GHAST_TEAR, 2), new ItemStack(Material.FEATHER, 16), new ItemStack(Material.SPIDER_EYE, 16)); + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + public static void setArcher(Player player) { + ItemStack helm = new ItemStack(Material.LEATHER_HELMET); + ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE); + ItemStack pants = new ItemStack(Material.LEATHER_LEGGINGS); + ItemStack boots = new ItemStack(Material.LEATHER_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + ItemStack bow = new ItemStack(Material.BOW); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + bow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, maxPower); + bow.addUnsafeEnchantment(Enchantment.ARROW_FIRE, maxFire); + bow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, maxInfinite); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + + player.getInventory().addItem(sword, bow, new ItemStack(Material.ENDER_PEARL, 16), new ItemStack(Material.COOKED_BEEF, 32), new ItemStack(Material.ARROW, 1), new ItemStack(Material.SUGAR, 32)); + + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + public static void setBuilder(Player player) { + ItemStack helm = new ItemStack(Material.DIAMOND_HELMET); + ItemStack chest = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemStack pants = new ItemStack(Material.DIAMOND_LEGGINGS); + ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + + ItemStack pick = new ItemStack(Material.DIAMOND_PICKAXE); + pick.addEnchantment(Enchantment.DIG_SPEED, 5); + + ItemStack spade = new ItemStack(Material.DIAMOND_SPADE); + spade.addEnchantment(Enchantment.DIG_SPEED, 4); + player.getInventory().addItem(sword, + new ItemStack(Material.ENDER_PEARL, 16), + new ItemStack(Material.COOKED_BEEF, 32), + pick, + spade, + new ItemStack(Material.REDSTONE_BLOCK, 10), + new ItemStack(Material.GLASS, 64), + new ItemStack(Material.REDSTONE_COMPARATOR, 64), + new ItemStack(Material.WOOD_PLATE, 64), + new ItemStack(Material.FENCE, 64), + new ItemStack(Material.COOKED_BEEF, 16), + new ItemStack(Material.STRING, 64), + new ItemStack(Material.DIRT, 64), + new ItemStack(Material.COBBLESTONE, 64), + new ItemStack(Material.STONE, 64), + new ItemStack(Material.LOG, 64), + new ItemStack(Material.WATER_BUCKET, 64), + new ItemStack(Material.WOOL, 64), + new ItemStack(Material.STAINED_GLASS, 64, (short) 5), + new ItemStack(Material.COBBLESTONE_STAIRS, 64), + new ItemStack(Material.QUARTZ, 64), + new ItemStack(Material.GLOWSTONE), + new ItemStack(98, 64), + new ItemStack(Material.PISTON_BASE, 64), + new ItemStack(Material.SLIME_BALL, 64), + new ItemStack(Material.REDSTONE, 128), + new ItemStack(Material.HOPPER, 64), + new ItemStack(356, 64)); + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + +} \ No newline at end of file diff --git a/src/me/bruce/factions/LorexHCF.java b/src/me/bruce/factions/LorexHCF.java new file mode 100644 index 0000000..419b825 --- /dev/null +++ b/src/me/bruce/factions/LorexHCF.java @@ -0,0 +1,722 @@ +package me.bruce.factions; + +import java.io.File; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; +import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +import LorexMC.us.utils.internal.com.bruce.base.BasePlugin; +import lombok.Getter; +import me.bruce.factions.armors.PvpClassManager; +import me.bruce.factions.armors.bard.EffectRestorer; +import me.bruce.factions.commands.BallerRevive; +import me.bruce.factions.commands.BroadCastCommand; +import me.bruce.factions.commands.Buy; +import me.bruce.factions.commands.CobbleCommand; +import me.bruce.factions.commands.CoordsCommand; +import me.bruce.factions.commands.FRCOMMAND; +import me.bruce.factions.commands.FixCommand; +import me.bruce.factions.commands.FreezeCommand; +import me.bruce.factions.commands.GiveCrowbarCommand; +import me.bruce.factions.commands.GlowstoneMountain; +import me.bruce.factions.commands.GoppleCommand; +import me.bruce.factions.commands.HelpCommand; +import me.bruce.factions.commands.HubCommand; +import me.bruce.factions.commands.InveeSeeCommand; +import me.bruce.factions.commands.LFFCommand; +import me.bruce.factions.commands.LogoutCommand; +import me.bruce.factions.commands.MapKitCommand; +import me.bruce.factions.commands.MedicCommand; +import me.bruce.factions.commands.OresCommand; +import me.bruce.factions.commands.Panic; +import me.bruce.factions.commands.PingCommand; +import me.bruce.factions.commands.PlayTimeCommand; +import me.bruce.factions.commands.PotsCommand; +import me.bruce.factions.commands.Pro; +import me.bruce.factions.commands.PvPCommand; +import me.bruce.factions.commands.RefundCommand; +import me.bruce.factions.commands.RegenCommand; +import me.bruce.factions.commands.RenameCommand; +import me.bruce.factions.commands.RulesCommand; +import me.bruce.factions.commands.SPCOMMAND; +import me.bruce.factions.commands.SetPrefixCommand; +import me.bruce.factions.commands.SettingsCommand; +import me.bruce.factions.commands.SpawnCommand; +import me.bruce.factions.commands.StaffInformation; +import me.bruce.factions.commands.StaffSettings; +import me.bruce.factions.commands.StatsCommand; +import me.bruce.factions.commands.TLCommand; +import me.bruce.factions.commands.Tablist; +import me.bruce.factions.commands.TablistCommand; +import me.bruce.factions.commands.ToggleCapzoneEntryCommand; +import me.bruce.factions.commands.ToggleLightningCommand; +import me.bruce.factions.commands.Vip; +import me.bruce.factions.commands.WB; +import me.bruce.factions.commands.ZorexDeveloper; +import me.bruce.factions.commands.ZorexRevive; +import me.bruce.factions.commands.nv; +import me.bruce.factions.commands.randomtp; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.deathban.DeathbanListener; +import me.bruce.factions.deathban.DeathbanManager; +import me.bruce.factions.deathban.FlatFileDeathbanManager; +import me.bruce.factions.deathban.StaffReviveCommand; +import me.bruce.factions.deathban.lives.LivesExecutor; +import me.bruce.factions.economy.EconomyCommand; +import me.bruce.factions.economy.EconomyManager; +import me.bruce.factions.economy.FlatFileEconomyManager; +import me.bruce.factions.economy.PayCommand; +import me.bruce.factions.economy.ShopSignListener; +import me.bruce.factions.endoftheworld.EotwCommand; +import me.bruce.factions.endoftheworld.EotwHandler; +import me.bruce.factions.endoftheworld.EotwListener; +import me.bruce.factions.eventutils.CaptureZone; +import me.bruce.factions.eventutils.EventExecutor; +import me.bruce.factions.eventutils.EventScheduler; +import me.bruce.factions.faction.FactionExecutor; +import me.bruce.factions.faction.FactionManager; +import me.bruce.factions.faction.FactionMember; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.faction.FlatFileFactionManager; +import me.bruce.factions.faction.args.FactionClaimChunkArgument; +import me.bruce.factions.faction.claim.Claim; +import me.bruce.factions.faction.claim.ClaimHandler; +import me.bruce.factions.faction.claim.ClaimWandListener; +import me.bruce.factions.faction.claim.Subclaim; +import me.bruce.factions.faction.claim.SubclaimWandListener; +import me.bruce.factions.faction.type.CapturableFaction; +import me.bruce.factions.faction.type.ClaimableFaction; +import me.bruce.factions.faction.type.ConquestFaction; +import me.bruce.factions.faction.type.EndPortalFaction; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.faction.type.GlowstoneMountainFaction; +import me.bruce.factions.faction.type.KothFaction; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.faction.type.RoadFaction; +import me.bruce.factions.faction.type.SpawnFaction; +import me.bruce.factions.keysale.keysaleCommand; +import me.bruce.factions.koth.KothExecutor; +import me.bruce.factions.listener.AutoSmeltOreListener; +import me.bruce.factions.listener.BookDeenchantListener; +import me.bruce.factions.listener.BorderListener; +import me.bruce.factions.listener.BottledExpListener; +import me.bruce.factions.listener.ChatListener; +import me.bruce.factions.listener.Cooldowns; +import me.bruce.factions.listener.CoreListener; +import me.bruce.factions.listener.CreativeClickListener; +import me.bruce.factions.listener.CrowbarListener; +import me.bruce.factions.listener.DeathMessageListener; +import me.bruce.factions.listener.DeathSignListener; +import me.bruce.factions.listener.ElevatorListener; +import me.bruce.factions.listener.EndListener; +import me.bruce.factions.listener.EntityLimitListener; +import me.bruce.factions.listener.EventSignListener; +import me.bruce.factions.listener.ExpMultiplierListener; +import me.bruce.factions.listener.FactionListener; +import me.bruce.factions.listener.FastEverythingListener; +import me.bruce.factions.listener.FoundDiamondsListener; +import me.bruce.factions.listener.ItemRemoverListener; +import me.bruce.factions.listener.MineListener; +import me.bruce.factions.listener.PlayTimeManager; +import me.bruce.factions.listener.PortalListener; +import me.bruce.factions.listener.PotListener; +import me.bruce.factions.listener.ProtectionListener; +import me.bruce.factions.listener.SignSubclaimListener; +import me.bruce.factions.listener.StaffModeListener; +import me.bruce.factions.listener.StrengthListener; +import me.bruce.factions.listener.UnRepairableListener; +import me.bruce.factions.listener.UserManager; +import me.bruce.factions.listener.VanishListener; +import me.bruce.factions.listener.WorldListener; +import me.bruce.factions.listener.combatloggers.CombatLogListener; +import me.bruce.factions.listener.combatloggers.CustomEntityRegistration; +import me.bruce.factions.listener.fixes.ArmorFixListener; +import me.bruce.factions.listener.fixes.BlockHitFixListener; +import me.bruce.factions.listener.fixes.BlockJumpGlitchFixListener; +import me.bruce.factions.listener.fixes.BoatGlitchFixListener; +import me.bruce.factions.listener.fixes.ColonCommandFixListener; +import me.bruce.factions.listener.fixes.CreatureSpawn; +import me.bruce.factions.listener.fixes.EnchantLimitListener; +import me.bruce.factions.listener.fixes.EnderChestRemovalListener; +import me.bruce.factions.listener.fixes.HungerFixListener; +import me.bruce.factions.listener.fixes.InfinityArrowFixListener; +import me.bruce.factions.listener.fixes.PearlGlitchListener; +import me.bruce.factions.listener.fixes.PortalTrapFixListener; +import me.bruce.factions.listener.fixes.PotionLimitListener; +import me.bruce.factions.listener.fixes.VoidGlitchFixListener; +import me.bruce.factions.listener.render.ProtocolLibHook; +import me.bruce.factions.listener.render.VisualiseHandler; +import me.bruce.factions.listener.render.WallBorderListener; +import me.bruce.factions.prefix.PrefixInv; +import me.bruce.factions.prefix.PrefixMenu; +import me.bruce.factions.prefix.prefix; + +import me.bruce.factions.rank.RankCommand; +import me.bruce.factions.rank.RankExecutor; +import me.bruce.factions.reboot.rebootCommand; +import me.bruce.factions.scoreboard.ScoreboardHandler; +import me.bruce.factions.staff.StaffModeCommand; +import me.bruce.factions.staff.VanishCommand; +import me.bruce.factions.startoftheworld.SotwCommand; +import me.bruce.factions.startoftheworld.SotwListener; +import me.bruce.factions.startoftheworld.SotwTimer; +import me.bruce.factions.timer.TimerExecutor; +import me.bruce.factions.timer.TimerManager; +import me.bruce.factions.ymls.AThing; +import me.bruce.factions.ymls.SettingsYML; +import me.bruceboy.framework.commands.Fly; +import me.bruceboy.framework.commands.Gamemode; +import me.bruceboy.framework.commands.ListCommand; +import me.bruceboy.framework.commands.Teleport; +import me.bruceboy.framework.commands.tphere; +import me.tablist.api.tabapi.Tab; +import me.tablist.api.tablist.adapter.TablistAdapter; +//import src.me.bruceboy.tablist.lorexmc.utils.main.TabCreator; +import net.milkbowl.vault.chat.Chat; +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.permission.Permission; + +public class LorexHCF extends JavaPlugin { + public static Permission permission = null; + public static Economy economy = null; + public static Economy econ = null; + public static Chat chat = null; + public static final String PREFIX; + public static final String NOPLAYER; + public static final String PREFIXNOPERMS; + public static final String NOPERMS; + AThing utils = new AThing(this); + + + @Getter + private static LorexHCF instance; + @Getter + private PlayTimeManager playTimeManager; + @Getter + private Random random = new Random(); + @Getter + private ClaimHandler claimHandler; + @Getter + private DeathbanManager deathbanManager; + @Getter + private EconomyManager economyManager; + @Getter + private EffectRestorer effectRestorer; + @Getter + private EotwHandler eotwHandler; + @Getter + private EventScheduler eventScheduler; + @Getter + private FactionManager factionManager; + @Getter + private FoundDiamondsListener foundDiamondsListener; + @Getter + private PvpClassManager pvpClassManager; + @Getter + private ScoreboardHandler scoreboardHandler; + @Getter + private SotwTimer sotwTimer; + @Getter + private static me.bruce.factions.keysale.keysaletimer keysaletimer; + @Getter + private static me.bruce.factions.reboot.reboottimer reboottimer; + @Getter + private TimerManager timerManager; + @Getter + private FactionUser factionUser; + @Getter + private UserManager userManager; + @Getter + private VisualiseHandler visualiseHandler; + @Getter + private WorldEditPlugin worldEdit; + + private CombatLogListener combatLogListener; + + public CombatLogListener getCombatLogListener() { + return this.combatLogListener; + } + public static String PREFIX1 = ChatColor.GOLD + "" + ChatColor.BOLD + "Zorex" + ChatColor.GRAY + " » "; + + public void resetGlowstoneMountain() { + for (int x = 502; x <= 582; x++) { + for (int y = 76; y <= 112; y++) { + for (int z = 594; z > 514; z--) { + Block block = Bukkit.getWorld("world_nether") + .getBlockAt(new Location(Bukkit.getWorld("world_nether"), -1 * x, y, z)); + if (block.getType().equals(Material.AIR)) { + block.setType(Material.GLOWSTONE); + } + } + } + } + } + + @Override + public void onEnable() { + //new TabList(this, new me.bruceboy.tablist.lorexmc.utils.main.TabCreator()); + + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "HCF Enabled"); + setupEconomy(); + File file = new File(getDataFolder(), "config.yml"); + if (!file.exists()) { + this.getConfig().options().copyDefaults(true); + this.saveConfig(); + } + Cooldowns.createCooldown("medic_cooldown"); + Cooldowns.createCooldown("lff_cooldown"); + Cooldowns.createCooldown("revive_cooldown"); + + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7The core has been &aenabled!&7.")); + instance = this; + BasePlugin.getPlugin().init(this); + + ProtocolLibHook.hook(this); + + Plugin wep = getServer().getPluginManager().getPlugin("WorldEdit"); + Plugin kits = getServer().getPluginManager().getPlugin("VengefulKits"); + this.worldEdit = wep instanceof WorldEditPlugin && wep.isEnabled() ? (WorldEditPlugin) wep : null; + CustomEntityRegistration.registerCustomEntities(); + + SettingsYML.init(this); + this.effectRestorer = new EffectRestorer(this); + this.registerConfiguration(); + this.registerCommands(); + // getCommand("list").setExecutor(new ListCommand()); + //getCommand("fly").setExecutor(new Fly()); + getCommand("spawn").setExecutor(new SpawnCommand()); + getCommand("author").setExecutor(new ZorexDeveloper()); + getCommand("stats").setExecutor(new StatsCommand()); + this.registerManagers(); + this.registerListeners(); + this.setupPermissions(); + this.resetGlowstoneMountain(); + this.prefixcommands(); + this.registerEvents1(); + tab(); + + + new BukkitRunnable() { + @Override + public void run() { + getServer().broadcastMessage(ChatColor.RED.toString() + ChatColor.BOLD + "Saving" + "\n" + ChatColor.RED + + "All the faction data to the database."); + saveData(); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', + "&7&m----------------------------------------------")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', + "&cJoin our discord at: https://discord.gg/eZS8Brc")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', + "&7&m----------------------------------------------")); + } + }.runTaskTimerAsynchronously(this, TimeUnit.MINUTES.toMillis(10L), TimeUnit.SECONDS.toMillis(10L)); + } + public void tab() { + TablistAdapter ta = new TablistAdapter(this, utils); + Bukkit.getServer().getPluginManager().registerEvents(new Tab(this, utils, ta), this); + } + + + + + private void saveData() { + this.combatLogListener.removeCombatLoggers(); + this.deathbanManager.saveDeathbanData(); + this.economyManager.saveEconomyData(); + this.factionManager.saveFactionData(); + this.timerManager.saveTimerData(); + this.userManager.saveUserData(); + } + + @Override + public void onDisable() { + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Economy has been &asaved! &7(1/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Faction has been &asaved! &7(2/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Key Data has been &asaved! &7(3/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Cooldowns has been &asaved! &7(4/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Player Data has been &asaved! &7(5/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Player Vaults has been &asaved! &7(6/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Saving is now &acomplete!&7.")); + this.pvpClassManager.onDisable(); + this.scoreboardHandler.clearBoards(); + this.factionManager.saveFactionData(); + this.deathbanManager.saveDeathbanData(); + this.economyManager.saveEconomyData(); + this.factionManager.saveFactionData(); + this.timerManager.saveTimerData(); + this.userManager.saveUserData(); + this.playTimeManager.savePlaytimeData(); + this.saveData(); + + instance = null; // always initialise last + } + + public static Chat getChat() { + return LorexHCF.chat; + } + + private boolean setupPermissions() { + final RegisteredServiceProvider permissionProvider = this.getServer().getServicesManager() + .getRegistration((Class) Permission.class); + if (permissionProvider != null) { + permission = (Permission) permissionProvider.getProvider(); + } + return permission != null; + } + + private boolean setupChat() { + final RegisteredServiceProvider chatProvider = this.getServer().getServicesManager() + .getRegistration((Class) Chat.class); + if (chatProvider != null) { + LorexHCF.chat = (Chat) chatProvider.getProvider(); + } + return LorexHCF.chat != null; + } + + private boolean setupEconomy() { + if (getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = rsp.getProvider(); + return econ != null; + } + + private void registerConfiguration() { + ConfigurationSerialization.registerClass(CaptureZone.class); + ConfigurationSerialization.registerClass(Deathban.class); + ConfigurationSerialization.registerClass(Claim.class); + ConfigurationSerialization.registerClass(Subclaim.class); + ConfigurationSerialization.registerClass(Deathban.class); + ConfigurationSerialization.registerClass(FactionUser.class); + ConfigurationSerialization.registerClass(ClaimableFaction.class); + ConfigurationSerialization.registerClass(ConquestFaction.class); + ConfigurationSerialization.registerClass(CapturableFaction.class); + ConfigurationSerialization.registerClass(KothFaction.class); + ConfigurationSerialization.registerClass(EndPortalFaction.class); + ConfigurationSerialization.registerClass(Faction.class); + ConfigurationSerialization.registerClass(FactionMember.class); + ConfigurationSerialization.registerClass(PlayerFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.class); + ConfigurationSerialization.registerClass(SpawnFaction.class); + ConfigurationSerialization.registerClass(GlowstoneMountainFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.NorthRoadFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.EastRoadFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.SouthRoadFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.WestRoadFaction.class); + } + + public void registerListeners() { + PluginManager manager = this.getServer().getPluginManager(); + this.playTimeManager = new PlayTimeManager(this); + manager.registerEvents(this.playTimeManager, this); + // If Kit_MAP = true then this will enable and the false shit wont enable. + manager.registerEvents(this.combatLogListener = new CombatLogListener(this), this); + manager.registerEvents(new BlockHitFixListener(), this); + manager.registerEvents(new BlockJumpGlitchFixListener(), this); + manager.registerEvents(new BoatGlitchFixListener(), this); + manager.registerEvents(new BookDeenchantListener(), this); + manager.registerEvents(new FactionClaimChunkArgument(this), this); + manager.registerEvents(new BorderListener(), this); // I never fix the pearl pass border in this version might + // wanna fix it + manager.registerEvents(new CreatureSpawn(), this); + manager.registerEvents(new CobbleCommand(), this); + manager.registerEvents(new BottledExpListener(), this); + manager.registerEvents(new PortalTrapFixListener(this), this); + manager.registerEvents(new ChatListener(this), this); + manager.registerEvents(new ClaimWandListener(this), this); + manager.registerEvents(new CoreListener(this), this); + manager.registerEvents(new ElevatorListener(this), this); + manager.registerEvents(new CrowbarListener(this), this); + manager.registerEvents(new DeathMessageListener(this), this); + manager.registerEvents(new DeathSignListener(this), this); + manager.registerEvents(new PotsCommand(this), this); + manager.registerEvents(new SettingsCommand(), this); + manager.registerEvents(new Tablist(), this); + manager.registerEvents(new ShopSignListener(this), this); + + // If KIT_MAP = false then this will enable if its true this enables. + if (SettingsYML.KIT_MAP == false) { + manager.registerEvents(new DeathbanListener(this), this); + } + manager.registerEvents(new EnchantLimitListener(), this); + manager.registerEvents(new EnderChestRemovalListener(), this); + manager.registerEvents(new EntityLimitListener(), this); + manager.registerEvents(new EndListener(), this); + manager.registerEvents(new EotwListener(this), this); + manager.registerEvents(new EventSignListener(), this); + manager.registerEvents(new ExpMultiplierListener(), this); + manager.registerEvents(new FactionListener(this), this); + manager.registerEvents(this.foundDiamondsListener = new FoundDiamondsListener(this), this); + manager.registerEvents(new FastEverythingListener(this), this); + manager.registerEvents(new InfinityArrowFixListener(), this); + manager.registerEvents(new PearlGlitchListener(this), this); + manager.registerEvents(new PortalListener(this), this); + manager.registerEvents(new PotionLimitListener(), this); + manager.registerEvents(new ProtectionListener(this), this); + manager.registerEvents(new SubclaimWandListener(this), this); + manager.registerEvents(new SignSubclaimListener(this), this); + manager.registerEvents(new SotwListener(this), this); + manager.registerEvents(new VoidGlitchFixListener(), this); + manager.registerEvents(new UnRepairableListener(), this); + manager.registerEvents(new WallBorderListener(this), this); + manager.registerEvents(new AutoSmeltOreListener(), this); + manager.registerEvents(new WorldListener(this), this); + manager.registerEvents(new MineListener(this), this); + manager.registerEvents(new ItemRemoverListener(this), this); + manager.registerEvents(new PotListener(this), this); // this pot listener is aids btw + // manager.registerEvents(new GlowstoneListener (this), this); + manager.registerEvents(new StrengthListener(), this); + manager.registerEvents(new CreativeClickListener(), this); + manager.registerEvents(new ArmorFixListener(), this); + manager.registerEvents(new HungerFixListener(this), this); + manager.registerEvents(new ColonCommandFixListener(), this); + manager.registerEvents(new RefundCommand(this), this); + manager.registerEvents(new InveeSeeCommand(), this); + //manager.registerEvents((Listener)new StaffModeListener(), (Plugin)this); + //manager.registerEvents((Listener)new VanishListener(), this); + manager.registerEvents(new me.bruce.factions.KIts.KitsInteract(), this); + manager.registerEvents(new me.bruce.factions.KIts.KitsInvClick(), this); + manager.registerEvents(new StaffSettings(), this); + manager.registerEvents(new TablistCommand(), this); + } + + private void registerCommands() { + getCommand("vanish").setExecutor(new VanishCommand()); + getCommand("zorex").setExecutor(new ZorexRevive(this)); + getCommand("vip").setExecutor(new Vip(this)); + getCommand("pro").setExecutor(new Pro(this)); + getCommand("rules").setExecutor(new RulesCommand()); + getCommand("baller").setExecutor(new BallerRevive(this)); + getCommand("tl").setExecutor(new TLCommand()); + getCommand("invsee").setExecutor(new InveeSeeCommand()); + getCommand("fix").setExecutor(new FixCommand()); + getCommand("broadcast").setExecutor(new BroadCastCommand()); + getCommand("cobble").setExecutor(new CobbleCommand()); + getCommand("hub").setExecutor(new HubCommand(this)); + getCommand("amethyst").setExecutor(new MedicCommand(this)); + getCommand("crowgive").setExecutor(new GiveCrowbarCommand()); + getCommand("hcfhelp").setExecutor(new HelpCommand()); + getCommand("coords").setExecutor(new CoordsCommand()); + getCommand("conquest").setExecutor(new me.bruce.factions.conquest.ConquestExecutor(this)); + getCommand("economy").setExecutor(new EconomyCommand(this)); + getCommand("refund").setExecutor(new RefundCommand(this)); + getCommand("eotw").setExecutor(new EotwCommand(this)); + getCommand("panic").setExecutor(new Panic()); + getCommand("tablistgui").setExecutor(new TablistCommand()); + getCommand("event").setExecutor(new EventExecutor(this)); + getCommand("hcfhelp").setExecutor(new HelpCommand()); + getCommand("faction").setExecutor(new FactionExecutor(this)); + getCommand("tp").setExecutor(new Teleport()); + getCommand("wb").setExecutor(new WB()); + getCommand("nv").setExecutor(new nv()); + getCommand("here").setExecutor(new tphere()); +// getCommand("vanish").setExecutor((CommandExecutor)new VanishCommand()); + getCommand("gopple").setExecutor(new GoppleCommand(this)); + getCommand("gamemode").setExecutor( new Gamemode()); + getCommand("koth").setExecutor(new KothExecutor(this)); + getCommand("lives").setExecutor(new LivesExecutor(this)); + getCommand("ping").setExecutor(new PingCommand()); + //getCommand("slowchat").setExecutor(new SlowChat(this)); + //getCommand("disablechat").setExecutor(new DisableChat(this)); + getCommand("freeze").setExecutor(new FreezeCommand(this)); + getCommand("logout").setExecutor(new LogoutCommand(this)); + //tCommand("staffmode").setExecutor((CommandExecutor)new StaffModeCommand()); + getCommand("mapkit").setExecutor(new MapKitCommand(this)); + getCommand("pay").setExecutor(new PayCommand(this)); + getCommand("tablist").setExecutor(new Tablist()); + getCommand("sp").setExecutor(new SPCOMMAND()); + getCommand("fr").setExecutor(new FRCOMMAND()); + getCommand("pvptimer").setExecutor(new PvPCommand(this)); + getCommand("reboot").setExecutor(new rebootCommand(this)); + getCommand("staffgui").setExecutor(new StaffSettings()); + getCommand("pots").setExecutor(new PotsCommand(this)); + getCommand("regen").setExecutor(new RegenCommand(this)); + getCommand("keysale").setExecutor(new keysaleCommand(this)); + getCommand("sotw").setExecutor(new SotwCommand(this)); + getCommand("staffrevive").setExecutor(new StaffReviveCommand(this)); + getCommand("staffguide").setExecutor(new StaffInformation()); + getCommand("timer").setExecutor(new TimerExecutor(this)); + getCommand("lff").setExecutor(new LFFCommand(this)); + getCommand("togglecapzoneentry").setExecutor(new ToggleCapzoneEntryCommand(this)); + getCommand("togglelightning").setExecutor(new ToggleLightningCommand(this)); + getCommand("rename").setExecutor(new RenameCommand(this)); + getCommand("ores").setExecutor(new OresCommand(this)); + getCommand("playtime").setExecutor(new PlayTimeCommand()); + getCommand("settings").setExecutor(new SettingsCommand()); + getCommand("rank").setExecutor(new RankExecutor(this)); + getCommand("glowstonemountain").setExecutor(new GlowstoneMountain(this)); + getCommand("buy").setExecutor(new Buy()); + getCommand("setprefix").setExecutor(new SetPrefixCommand()); + getCommand("randomtp").setExecutor(new randomtp()); + getCommand("staffgui").setExecutor(new StaffSettings()); + + Map> map = getDescription().getCommands(); + for (Map.Entry> entry : map.entrySet()) { + PluginCommand command = getCommand(entry.getKey()); + command.setPermission("zorex." + entry.getKey()); + command.setPermissionMessage(ChatColor.RED + "You do not have permissions to execute this command."); + } + } + private void registerManagers() { + this.claimHandler = new ClaimHandler(this); + this.deathbanManager = new FlatFileDeathbanManager(this); + this.economyManager = new FlatFileEconomyManager(this); + this.eotwHandler = new EotwHandler(this); + this.eventScheduler = new EventScheduler(this); + this.factionManager = new FlatFileFactionManager(this); + this.pvpClassManager = new PvpClassManager(this); + this.sotwTimer = new SotwTimer(); + this.keysaletimer = new me.bruce.factions.keysale.keysaletimer(); + this.reboottimer = new me.bruce.factions.reboot.reboottimer(); + this.timerManager = new TimerManager(this); // needs to be registered before ScoreboardHandler + this.scoreboardHandler = new ScoreboardHandler(this); + this.userManager = new UserManager(this); + this.visualiseHandler = new VisualiseHandler(); + } + + public void prefixcommands() { + this.getCommand("prefix").setExecutor((CommandExecutor)new prefix()); + } + private void registerEvents1() { + final PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents((Listener)new PrefixMenu(), (Plugin)this); + pm.registerEvents((Listener)new PrefixInv(), (Plugin)this); + + } + + + private void registerCooldowns() { + Cooldowns.createCooldown("medic_cooldown"); + } + + + + public PlayTimeManager getPlayTimeManager() { + return this.playTimeManager; + } + + public static LorexHCF getInstance() { + return LorexHCF.instance; + } + + public Random getRandom() { + return this.random; + } + + + + public ClaimHandler getClaimHandler() { + return this.claimHandler; + } + + public DeathbanManager getDeathbanManager() { + return this.deathbanManager; + } + + public EconomyManager getEconomyManager() { + return this.economyManager; + } + + public EffectRestorer getEffectRestorer() { + return this.effectRestorer; + } + + public EotwHandler getEotwHandler() { + return this.eotwHandler; + } + + public static SotwTimer getSotwRunnable() { + return LorexHCF.getSotwRunnable(); + } + + public FactionUser getFactionUser() { + return this.factionUser; + } + + public EventScheduler getEventScheduler() { + return this.eventScheduler; + } + + public FactionManager getFactionManager() { + return this.factionManager; + } + + public FoundDiamondsListener getFoundDiamondsListener() { + return this.foundDiamondsListener; + } + + public PvpClassManager getPvpClassManager() { + return this.pvpClassManager; + } + + public ScoreboardHandler getScoreboardHandler() { + return this.scoreboardHandler; + } + public static me.bruce.factions.keysale.keysaletimer getkeysalerunnable() { + return LorexHCF.getkeysalerunnable(); + } + public static me.bruce.factions.keysale.keysaletimer getkeysaletimer() { + return keysaletimer; + } + public static me.bruce.factions.reboot.reboottimer getreboottimer() { + return reboottimer; + } + + + + public SotwTimer getSotwTimer() { + return this.sotwTimer; + } + public me.bruce.factions.reboot.reboottimer getrebootrunnable() { + return this.reboottimer; + } + + public TimerManager getTimerManager() { + return this.timerManager; + } + + public UserManager getUserManager() { + return this.userManager; + } + + public VisualiseHandler getVisualiseHandler() { + return this.visualiseHandler; + } + + public WorldEditPlugin getWorldEdit() { + return this.worldEdit; + } + + public static ChatColor getRemaining(long remaining, boolean b, boolean c) { + // TODO Auto-generated method stub + return null; + } + static { + PREFIX = ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY; + NOPLAYER = ChatColor.RED + "You must be a player to use this command. "; + PREFIXNOPERMS = ChatColor.RED + "You lack the sufficient permissions to use this prefix. "; + NOPERMS = ChatColor.RED + "You lack the sufficient permissions to execute this command. "; + } + +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/PvpClass.java b/src/me/bruce/factions/armors/PvpClass.java new file mode 100644 index 0000000..1dff36a --- /dev/null +++ b/src/me/bruce/factions/armors/PvpClass.java @@ -0,0 +1,83 @@ +package me.bruce.factions.armors; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * Represents a class that can apply PVP buffs for players. + */ +public abstract class PvpClass { + + public static final long DEFAULT_MAX_DURATION = TimeUnit.MINUTES.toMillis(8L); + + protected final Set passiveEffects = new HashSet<>(); + protected final String name; + protected final long warmupDelay; + + public PvpClass(String name, long warmupDelay) { + this.name = name; + this.warmupDelay = warmupDelay; + } + + /** + * Gets the name of this {@link PvpClass}. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the warmup delay of this {@link PvpClass}. + * + * @return the warmup delay in milliseconds + */ + public long getWarmupDelay() { + return warmupDelay; + } + + /** + * Method called when a {@link Player} equips a {@link PvpClass}. + * + * @param player + * the equipping {@link Player} + * @return true if successfully equipped + */ + public boolean onEquip(Player player) { + for (PotionEffect effect : passiveEffects) { + player.addPotionEffect(effect, true); + } + + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.YELLOW + name + " has been activated."); + return true; + } + + /** + * Method called when a {@link Player} unequips a {@link PvpClass}. + * + * @param player + * the unequipping {@link Player} + */ + public void onUnequip(Player player) { + for (PotionEffect effect : passiveEffects) { + for (PotionEffect active : player.getActivePotionEffects()) { + if (active.getDuration() > DEFAULT_MAX_DURATION && active.getType().equals(effect.getType()) + && active.getAmplifier() == effect.getAmplifier()) { + player.removePotionEffect(effect.getType()); + break; + } + } + } + + player.sendMessage(ChatColor.RED + name + " has been deactivated."); + } + + // TODO: More automated method + public abstract boolean isApplicableFor(Player player); +} diff --git a/src/me/bruce/factions/armors/PvpClassManager.java b/src/me/bruce/factions/armors/PvpClassManager.java new file mode 100644 index 0000000..3239a60 --- /dev/null +++ b/src/me/bruce/factions/armors/PvpClassManager.java @@ -0,0 +1,103 @@ +package me.bruce.factions.armors; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.armors.archer.ArcherClass; +import me.bruce.factions.armors.bard.BardClass; +import me.bruce.factions.armors.event.PvpClassEquipEvent; +import me.bruce.factions.armors.event.PvpClassUnequipEvent; +import me.bruce.factions.armors.miner.MinerClass; +import me.bruce.factions.armors.rogue.RogueClass; + +import javax.annotation.Nullable; +import java.util.*; + +public class PvpClassManager implements Listener { + + // Mapping to get the PVP Class a player has equipped. + private final Map equippedClassMap = new HashMap<>(); + + private final List pvpClasses = new ArrayList<>(); + + public PvpClassManager(LorexHCF plugin) { + pvpClasses.add(new ArcherClass(plugin)); + pvpClasses.add(new BardClass(plugin)); + pvpClasses.add(new MinerClass(plugin)); + pvpClasses.add(new RogueClass(plugin)); + + Bukkit.getPluginManager().registerEvents(this, plugin); + for (PvpClass pvpClass : pvpClasses) { + if (pvpClass instanceof Listener) { + plugin.getServer().getPluginManager().registerEvents((Listener) pvpClass, plugin); + } + } + } + + public void onDisable() { + for (Map.Entry entry : new HashMap<>(equippedClassMap).entrySet()) { + this.setEquippedClass(Bukkit.getPlayer(entry.getKey()), null); + } + + this.pvpClasses.clear(); + this.equippedClassMap.clear(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerDeath(PlayerDeathEvent event) { + setEquippedClass(event.getEntity(), null); + } + + /** + * Gets the {@link PvpClass}es held by this manager + * + * @return set of {@link PvpClass}es + */ + public Collection getPvpClasses() { + return pvpClasses; + } + + /** + * Gets the equipped {@link PvpClass} of a {@link Player}. + * + * @param player + * the {@link Player} to get for + * @return the equipped {@link PvpClass} + */ + public PvpClass getEquippedClass(Player player) { + synchronized (equippedClassMap) { + return equippedClassMap.get(player.getUniqueId()); + } + } + + public boolean hasClassEquipped(Player player, PvpClass pvpClass) { + return getEquippedClass(player) == pvpClass; + } + + /** + * Sets the equipped {@link PvpClass} of a {@link Player}. + * + * @param player + * the {@link Player} to set for + * @param pvpClass + * the class to equip or null to un-equip active + */ + public void setEquippedClass(Player player, @Nullable PvpClass pvpClass) { + if (pvpClass == null) { + PvpClass equipped = this.equippedClassMap.remove(player.getUniqueId()); + if (equipped != null) { + equipped.onUnequip(player); + Bukkit.getPluginManager().callEvent(new PvpClassUnequipEvent(player, equipped)); + } + } else if (pvpClass.onEquip(player) && pvpClass != this.getEquippedClass(player)) { + equippedClassMap.put(player.getUniqueId(), pvpClass); + Bukkit.getPluginManager().callEvent(new PvpClassEquipEvent(player, pvpClass)); + } + } +} diff --git a/src/me/bruce/factions/armors/archer/ArcherClass.java b/src/me/bruce/factions/armors/archer/ArcherClass.java new file mode 100644 index 0000000..9de3461 --- /dev/null +++ b/src/me/bruce/factions/armors/archer/ArcherClass.java @@ -0,0 +1,217 @@ +package me.bruce.factions.armors.archer; + +import gnu.trove.map.TObjectLongMap; +import gnu.trove.map.hash.TObjectLongHashMap; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; + +import java.util.HashMap; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.time.DurationFormatUtils; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.projectiles.ProjectileSource; + +public class ArcherClass extends PvpClass implements Listener { + private static final PotionEffect ARCHER_CRITICAL_EFFECT = new PotionEffect(PotionEffectType.SLOW, 60, 255); + private static final int MARK_TIMEOUT_SECONDS = 15; + private static final int MARK_EXECUTION_LEVEL = 3; + private static final float MINIMUM_FORCE = 0.5F; + public static final HashMap TAGGED = new HashMap(); + private static final PotionEffect ARCHER_SPEED_EFFECT = new PotionEffect(PotionEffectType.SPEED, 160, 3); + private static final PotionEffect ARCHER_JUMP_EFFECT = new PotionEffect(PotionEffectType.JUMP, 160, 3); + private static final long ARCHER_SPEED_COOLDOWN_DELAY = TimeUnit.SECONDS.toMillis(45L); + private static final long ARCHER_JUMP_COOLDOWN_DELAY = TimeUnit.MINUTES.toMillis(1L); + public static final TObjectLongMap archerSpeedCooldowns = new TObjectLongHashMap(); + private final TObjectLongMap archerJumpCooldowns = new TObjectLongHashMap(); + private final LorexHCF plugin; + private static Random random = new Random(); + + public ArcherClass(LorexHCF plugin) { + super("Archer", TimeUnit.SECONDS.toMillis(5L)); + this.plugin = plugin; + this.passiveEffects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2)); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityDamage(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + Entity damager = event.getDamager(); + if (((entity instanceof Player)) && ((damager instanceof Arrow))) { + Arrow arrow = (Arrow) damager; + ProjectileSource source = arrow.getShooter(); + if ((source instanceof Player)) { + Player damaged = (Player) event.getEntity(); + Player shooter = (Player) source; + PvpClass equipped = this.plugin.getPvpClassManager().getEquippedClass(shooter); + if ((equipped == null) || (!equipped.equals(this))) { + return; + } + if ((this.plugin.getTimerManager().archerTimer.getRemaining((Player) entity) == 0L) + || (this.plugin.getTimerManager().archerTimer.getRemaining((Player) entity) < TimeUnit.SECONDS + .toMillis(5L))) { + if ((this.plugin.getPvpClassManager().getEquippedClass(damaged) != null) + && (this.plugin.getPvpClassManager().getEquippedClass(damaged).equals(this))) { + return; + } + double distance = shooter.getLocation().distance(damaged.getLocation()); + shooter.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&e[&9Arrow Range &e(&c" + String.format("%.1f", new Object[] { Double.valueOf(distance) }) + + "&e)] " + "&6Marked " + damaged.getName() + " &6for 6 seconds. &9&l(1 heart)")); + + damaged.sendMessage(ChatColor.GOLD + "You were archer tagged by " + ChatColor.RED + + shooter.getName() + ChatColor.GOLD + " from " + ChatColor.RED + + String.format("%.1f", new Object[] { Double.valueOf(distance) }) + ChatColor.GOLD + + " blocks away."); + + LeatherArmorMeta helmMeta = (LeatherArmorMeta) shooter.getInventory().getHelmet().getItemMeta(); + LeatherArmorMeta chestMeta = (LeatherArmorMeta) shooter.getInventory().getChestplate() + .getItemMeta(); + LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) shooter.getInventory().getLeggings() + .getItemMeta(); + LeatherArmorMeta bootsMeta = (LeatherArmorMeta) shooter.getInventory().getBoots().getItemMeta(); + Color green = Color.fromRGB(6717235); + + double r = random.nextDouble(); + r = random.nextDouble(); + if ((r <= 0.5D) && (helmMeta.getColor().equals(green)) && (chestMeta.getColor().equals(green)) + && (leggingsMeta.getColor().equals(green)) && (bootsMeta.getColor().equals(green))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is green, you gave " + damaged.getName() + + " the poison effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is green, you were given the poison effect for 6 seconds..."); + } + Color blue = Color.fromRGB(3361970); + if ((r <= 0.5D) && (helmMeta.getColor().equals(blue)) && (chestMeta.getColor().equals(blue)) + && (leggingsMeta.getColor().equals(blue)) && (bootsMeta.getColor().equals(blue))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is blue, you gave " + damaged.getName() + + " the slowness effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is blue, you were given the slowness effect for 6 seconds..."); + } + Color gray = Color.fromRGB(5000268); + if ((r <= 0.5D) && (helmMeta.getColor().equals(gray)) && (chestMeta.getColor().equals(gray)) + && (leggingsMeta.getColor().equals(gray)) && (bootsMeta.getColor().equals(gray))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is gray, you gave " + damaged.getName() + + " the blindness effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is gray, you were given the blindness effect for 6 seconds..."); + } + Color black = Color.fromRGB(1644825); + if ((r <= 0.2D) && (helmMeta.getColor().equals(black)) && (chestMeta.getColor().equals(black)) + && (leggingsMeta.getColor().equals(black)) && (bootsMeta.getColor().equals(black))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is black, you gave " + damaged.getName() + + " the wither effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is black, you were given the wither effect for 6 seconds..."); + } + } + } + } + } + + @EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH) + public void onArcherSpeedClick(PlayerInteractEvent event) { + Action action = event.getAction(); + if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) && (event.hasItem()) + && (event.getItem().getType() == Material.SUGAR)) { + if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) { + return; + } + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + long timestamp = ArcherClass.archerSpeedCooldowns.get(uuid); + long millis = System.currentTimeMillis(); + long remaining = timestamp == ArcherClass.archerSpeedCooldowns.getNoEntryValue() ? -1L : timestamp - millis; + if (remaining > 0L) { + player.sendMessage(ChatColor.RED + "Cannot use Speed Boost for another " + + DurationFormatUtils.formatDurationWords(remaining, true, true) + "."); + } else { + ItemStack stack = player.getItemInHand(); + if (stack.getAmount() == 1) { + player.setItemInHand(new ItemStack(Material.AIR, 1)); + } else { + stack.setAmount(stack.getAmount() - 1); + } + player.sendMessage(ChatColor.GREEN + "Speed 4 activated for 7 seconds."); + + this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_SPEED_EFFECT); + ArcherClass.archerSpeedCooldowns.put(event.getPlayer().getUniqueId(), + System.currentTimeMillis() + ARCHER_SPEED_COOLDOWN_DELAY); + } + } + } + + @EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH) + public void onArcherJumpClick(PlayerInteractEvent event) { + Action action = event.getAction(); + if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) && (event.hasItem()) + && (event.getItem().getType() == Material.FEATHER)) { + if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) { + return; + } + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + long timestamp = this.archerJumpCooldowns.get(uuid); + long millis = System.currentTimeMillis(); + long remaining = timestamp == this.archerJumpCooldowns.getNoEntryValue() ? -1L : timestamp - millis; + if (remaining > 0L) { + player.sendMessage(ChatColor.RED + "Cannot use Jump Boost for another " + + DurationFormatUtils.formatDurationWords(remaining, true, true) + "."); + } else { + ItemStack stack = player.getItemInHand(); + if (stack.getAmount() == 1) { + player.setItemInHand(new ItemStack(Material.AIR, 1)); + } else { + stack.setAmount(stack.getAmount() - 1); + } + player.sendMessage(ChatColor.GREEN + "Jump Boost 4 activated for 7 seconds."); + + this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_JUMP_EFFECT); + this.archerJumpCooldowns.put(event.getPlayer().getUniqueId(), + System.currentTimeMillis() + ARCHER_JUMP_COOLDOWN_DELAY); + } + } + } + + @Override + public boolean isApplicableFor(Player player) { + PlayerInventory playerInventory = player.getInventory(); + ItemStack helmet = playerInventory.getHelmet(); + if ((helmet == null) || (helmet.getType() != Material.LEATHER_HELMET)) { + return false; + } + ItemStack chestplate = playerInventory.getChestplate(); + if ((chestplate == null) || (chestplate.getType() != Material.LEATHER_CHESTPLATE)) { + return false; + } + ItemStack leggings = playerInventory.getLeggings(); + if ((leggings == null) || (leggings.getType() != Material.LEATHER_LEGGINGS)) { + return false; + } + ItemStack boots = playerInventory.getBoots(); + return (boots != null) && (boots.getType() == Material.LEATHER_BOOTS); + } +} diff --git a/src/me/bruce/factions/armors/archer/ArcherMark.java b/src/me/bruce/factions/armors/archer/ArcherMark.java new file mode 100644 index 0000000..deb8809 --- /dev/null +++ b/src/me/bruce/factions/armors/archer/ArcherMark.java @@ -0,0 +1,52 @@ +package me.bruce.factions.armors.archer; + +import javax.annotation.Nonnull; +import org.bukkit.scheduler.BukkitTask; + +public class ArcherMark implements Comparable { + public BukkitTask decrementTask; + public int currentLevel; + + public void reset() { + if (this.decrementTask != null) { + this.decrementTask.cancel(); + this.decrementTask = null; + } + this.currentLevel = 0; + } + + public int incrementMark() { + return ++this.currentLevel; + } + + public int decrementMark() { + return --this.currentLevel; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ArcherMark)) { + return false; + } + ArcherMark that = (ArcherMark) o; + if (this.currentLevel != that.currentLevel) { + return false; + } + return this.decrementTask != null ? this.decrementTask.equals(that.decrementTask) : that.decrementTask == null; + } + + @Override + public int hashCode() { + int result = this.decrementTask != null ? this.decrementTask.hashCode() : 0; + result = 31 * result + this.currentLevel; + return result; + } + + @Override + public int compareTo(@Nonnull ArcherMark archerMark) { + return Integer.compare(this.currentLevel, archerMark.currentLevel); + } +} diff --git a/src/me/bruce/factions/armors/bard/BardClass.java b/src/me/bruce/factions/armors/bard/BardClass.java new file mode 100644 index 0000000..4dcf958 --- /dev/null +++ b/src/me/bruce/factions/armors/bard/BardClass.java @@ -0,0 +1,364 @@ +package me.bruce.factions.armors.bard; + +import java.util.Collection; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import LorexMC.us.utils.*; +import LorexMC.us.utils.other.chat.Lang; +import gnu.trove.map.TObjectLongMap; +import gnu.trove.map.hash.TObjectLongHashMap; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.faction.type.PlayerFaction; + +public class BardClass extends PvpClass implements Listener { + public static final int HELD_EFFECT_DURATION_TICKS = 100; // the amount of time in ticks to apply a Held potion + // effect for faction members + + private static final long BUFF_COOLDOWN_MILLIS = TimeUnit.SECONDS.toMillis(10L); // time in milliseconds for Bard + // buff cooldowns + private static final int TEAMMATE_NEARBY_RADIUS = 25; + private static final long HELD_REAPPLY_TICKS = 20L; + private static final String MARK = BukkitUtils.STRAIGHT_LINE_DEFAULT.substring(0, 8); + private final Map bardDataMap = new HashMap<>(); + private final Map bardEffects = new EnumMap<>(Material.class); + private final LorexHCF plugin; + private final TObjectLongMap msgCooldowns = new TObjectLongHashMap<>(); + + public BardClass(LorexHCF plugin) { + super("Bard", TimeUnit.SECONDS.toMillis(1L)); + this.plugin = plugin; + + this.passiveEffects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + this.bardEffects.put(Material.WHEAT, new BardEffect(35, new PotionEffect(PotionEffectType.SATURATION, 120, 1), + new PotionEffect(PotionEffectType.SATURATION, 100, 0))); + this.bardEffects.put(Material.SUGAR, new BardEffect(35, new PotionEffect(PotionEffectType.SPEED, 120, 2), + new PotionEffect(PotionEffectType.SPEED, 100, 1))); + this.bardEffects.put(Material.BLAZE_POWDER, + new BardEffect(45, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 120, 1), + new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, 0))); + this.bardEffects.put(Material.IRON_INGOT, + new BardEffect(35, new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 80, 2), + new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 100, 0))); + this.bardEffects.put(Material.GHAST_TEAR, + new BardEffect(30, new PotionEffect(PotionEffectType.REGENERATION, 60, 2), + new PotionEffect(PotionEffectType.REGENERATION, 100, 0))); + this.bardEffects.put(Material.FEATHER, new BardEffect(40, new PotionEffect(PotionEffectType.JUMP, 120, 2), + new PotionEffect(PotionEffectType.JUMP, 100, 0))); + this.bardEffects.put(Material.SPIDER_EYE, + new BardEffect(55, new PotionEffect(PotionEffectType.WITHER, 100, 1), null)); + this.bardEffects.put(Material.MAGMA_CREAM, + new BardEffect(10, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 900, 0), + new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 120, 0))); + } + + @Override + public boolean onEquip(Player player) { + if (plugin.getTimerManager().getCombatTimer().getRemaining(player) > 0L) { + player.sendMessage(ChatColor.RED + "You cannot equip the " + getName() + " Class whilst PVP Protected."); + return false; + } + + if (!super.onEquip(player)) { + return false; + } + + BardData bardData = new BardData(); + bardDataMap.put(player.getUniqueId(), bardData); + bardData.startEnergyTracking(); + bardData.heldTask = new BukkitRunnable() { + int lastEnergy; + + @Override + public void run() { + // Apply the bard effects here. + ItemStack held = player.getItemInHand(); + if (held != null) { + BardEffect bardEffect = bardEffects.get(held.getType()); + if (bardEffect == null) + return; + + if (bardEffect.heldable.getType() == PotionEffectType.JUMP) { + plugin.getEffectRestorer().setRestoreEffect(player, bardEffect.heldable); + } + + if (!plugin.getFactionManager().getFactionAt(player.getLocation()).isSafezone()) { + // Apply the held effect to faction members. + PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); + if (playerFaction != null) { + Collection nearbyEntities = player.getNearbyEntities(TEAMMATE_NEARBY_RADIUS, + TEAMMATE_NEARBY_RADIUS, TEAMMATE_NEARBY_RADIUS); + nearbyEntities.stream().filter(nearby -> nearby instanceof Player && !player.equals(nearby)) + .forEach(nearby -> { + Player target = (Player) nearby; + if (playerFaction.getMembers().containsKey(target.getUniqueId())) { + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.heldable); + } + }); + } + } + } + + int energy = (int) getEnergy(player); + // the -1 check is for offsets with the energy per millisecond + if (energy != 0 && energy != lastEnergy + && (energy % 10 == 0 || lastEnergy - energy - 1 > 0 || energy == BardData.MAX_ENERGY)) { + lastEnergy = energy; + player.sendMessage(ChatColor.GOLD + name + " Energy is now at " + ChatColor.RED + energy + + ChatColor.GOLD + '.'); + } + } + }.runTaskTimer(plugin, 0L, HELD_REAPPLY_TICKS); + return true; + } + + @Override + public void onUnequip(Player player) { + super.onUnequip(player); + clearBardData(player.getUniqueId()); + } + + private void clearBardData(UUID uuid) { + BardData bardData = bardDataMap.remove(uuid); + if (bardData != null && bardData.getHeldTask() != null) { + ((BukkitTask) bardData.getHeldTask()).cancel(); + } + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent event) { + clearBardData(event.getPlayer().getUniqueId()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerKick(PlayerKickEvent event) { + clearBardData(event.getPlayer().getUniqueId()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onItemHeld(PlayerItemHeldEvent event) { + Player player = event.getPlayer(); + PvpClass equipped = plugin.getPvpClassManager().getEquippedClass(player); + if (equipped == null || !equipped.equals(this)) { + return; + } + + UUID uuid = player.getUniqueId(); + long lastMessage = msgCooldowns.get(uuid); + long millis = System.currentTimeMillis(); + if (lastMessage != msgCooldowns.getNoEntryValue() && lastMessage - millis > 0L) { + return; + } + + ItemStack newStack = player.getInventory().getItem(event.getNewSlot()); + if (newStack != null) { + BardEffect bardEffect = bardEffects.get(newStack.getType()); + if (bardEffect != null) { + msgCooldowns.put(uuid, millis + 1500L); + player.sendMessage(ChatColor.GOLD + BukkitUtils.STRAIGHT_LINE_DEFAULT); + player.sendMessage(ChatColor.GOLD + "Bard Effect: " + ChatColor.GOLD); + player.sendMessage(ChatColor.GOLD + "\u00bb " + ChatColor.YELLOW + "Clickable Effect: " + ChatColor.AQUA + + Lang.fromPotionEffectType(bardEffect.clickable.getType()) + ' ' + + (bardEffect.clickable.getAmplifier() + 1) + ChatColor.GRAY + " (" + + (bardEffect.clickable.getDuration() / 20) + "s)"); + player.sendMessage(ChatColor.GOLD + "\u00bb " + ChatColor.YELLOW + "Energy Cost: " + ChatColor.AQUA + + bardEffect.energyCost); + player.sendMessage(ChatColor.GOLD + BukkitUtils.STRAIGHT_LINE_DEFAULT); + } + } + } + + @EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR) + public void onPlayerInteract(final PlayerInteractEvent event) { + if (!event.hasItem()) { + return; + } + final Action action = event.getAction(); + if (action == Action.RIGHT_CLICK_AIR || (!event.isCancelled() && action == Action.RIGHT_CLICK_BLOCK)) { + final ItemStack stack = event.getItem(); + final BardEffect bardEffect = this.bardEffects.get(stack.getType()); + if (bardEffect == null || bardEffect.clickable == null) { + return; + } + event.setUseItemInHand(Event.Result.DENY); + final Player player = event.getPlayer(); + final BardData bardData = this.bardDataMap.get(player.getUniqueId()); + if (bardData != null) { + if (!this.canUseBardEffect(player, bardData, bardEffect, true)) { + return; + } + if (stack.getAmount() > 1) { + stack.setAmount(stack.getAmount() - 1); + } else { + player.setItemInHand(new ItemStack(Material.AIR, 1)); + } + if (bardEffect != null + && !this.plugin.getFactionManager().getFactionAt(player.getLocation()).isSafezone()) { + final PlayerFaction playerFaction = this.plugin.getFactionManager().getPlayerFaction(player); + if (playerFaction != null && !bardEffect.clickable.getType().equals(PotionEffectType.WITHER)) { + final Collection nearbyEntities = player.getNearbyEntities(25.0, 25.0, 25.0); + for (final Entity nearby : nearbyEntities) { + if (nearby instanceof Player && !player.equals(nearby)) { + final Player target = (Player) nearby; + if (!playerFaction.getMembers().containsKey(target.getUniqueId())) { + continue; + } + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.clickable); + } + } + } else if (playerFaction != null + && bardEffect.clickable.getType().equals(PotionEffectType.WITHER)) { + final Collection nearbyEntities = player.getNearbyEntities(25.0, 25.0, 25.0); + for (final Entity nearby : nearbyEntities) { + if (nearby instanceof Player && !player.equals(nearby)) { + final Player target = (Player) nearby; + if (playerFaction.getMembers().containsKey(target.getUniqueId())) { + continue; + } + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.clickable); + } + } + } else if (bardEffect.clickable.getType().equals(PotionEffectType.WITHER)) { + final Collection nearbyEntities = player.getNearbyEntities(25.0, 25.0, 25.0); + nearbyEntities.stream().filter(nearby -> nearby instanceof Player && !player.equals(nearby)) + .forEach(nearby -> { + final Player target = (Player) nearby; + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.clickable); + }); + } + } + plugin.getEffectRestorer().setRestoreEffect(player, bardEffect.clickable); + bardData.setBuffCooldown(BUFF_COOLDOWN_MILLIS); + + double newEnergy = this.setEnergy(player, bardData.getEnergy() - bardEffect.energyCost); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&eYou have just used a &aBard Buff ðat cost you &lsome &eof your Energy.")); + // player.sendMessage(ChatColor.GOLD + "You have just used " + name + " buff " + + // ChatColor.RED + Lang.fromPotionEffectType(bardEffect.clickable.getType()) + ' + // ' + // + (bardEffect.clickable.getAmplifier() + 1) + ChatColor.GOLD + " costing you + // " + ChatColor.BOLD + bardEffect.energyCost + ChatColor.YELLOW + " energy. " + // + "Your energy is now " + ChatColor.GREEN + ((newEnergy * 10.0) / 10.0)/* + // TODO:neeeded? */+ ChatColor.YELLOW + '.'); + } + } + } + + private boolean canUseBardEffect(Player player, BardData bardData, BardEffect bardEffect, boolean sendFeedback) { + String errorFeedback = null; + double currentEnergy = bardData.getEnergy(); + if (bardEffect.energyCost > currentEnergy) { + errorFeedback = ChatColor.RED + "You need at least " + ChatColor.BOLD + bardEffect.energyCost + + ChatColor.RED + " energy to use this Bard buff, whilst you only have " + ChatColor.BOLD + + currentEnergy + ChatColor.RED + '.'; + } + + long remaining = bardData.getRemainingBuffDelay(); + if (remaining > 0L) { + errorFeedback = ChatColor.RED + "You cannot use this bard buff for another " + ChatColor.BOLD + + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + '.'; + } + + Faction factionAt = plugin.getFactionManager().getFactionAt(player.getLocation()); + if (factionAt.isSafezone()) { + errorFeedback = ChatColor.RED + "You may not use bard buffs in safe-zones."; + } + + if (sendFeedback && errorFeedback != null) { + player.sendMessage(errorFeedback); + } + + return errorFeedback == null; + } + + @Override + public boolean isApplicableFor(Player player) { + ItemStack helmet = player.getInventory().getHelmet(); + if (helmet == null || helmet.getType() != Material.GOLD_HELMET) + return false; + + ItemStack chestplate = player.getInventory().getChestplate(); + if (chestplate == null || chestplate.getType() != Material.GOLD_CHESTPLATE) + return false; + + ItemStack leggings = player.getInventory().getLeggings(); + if (leggings == null || leggings.getType() != Material.GOLD_LEGGINGS) + return false; + + ItemStack boots = player.getInventory().getBoots(); + return !(boots == null || boots.getType() != Material.GOLD_BOOTS); + } + + public long getRemainingBuffDelay(Player player) { + synchronized (bardDataMap) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + return bardData == null ? 0L : bardData.getRemainingBuffDelay(); + } + } + + /** + * Gets the energy of a {@link Player}. + * + * @param player + * the {@link Player} to get for + * @return the energy, or 0 if not tracking this player + */ + public double getEnergy(Player player) { + synchronized (bardDataMap) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + return bardData == null ? 0 : bardData.getEnergy(); + } + } + + public long getEnergyMillis(Player player) { + synchronized (bardDataMap) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + return bardData == null ? 0 : bardData.getEnergyMillis(); + } + } + + /** + * Sets the energy of a {@link Player}. + * + * @param player + * the {@link Player} to set for + * @param energy + * the energy amount to set + * @return the new energy amount + */ + public double setEnergy(Player player, double energy) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + if (bardData == null) + return 0.0; + + bardData.setEnergy(energy); + return bardData.getEnergy(); + } + +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/bard/BardData.java b/src/me/bruce/factions/armors/bard/BardData.java new file mode 100644 index 0000000..696e7b5 --- /dev/null +++ b/src/me/bruce/factions/armors/bard/BardData.java @@ -0,0 +1,68 @@ +package me.bruce.factions.armors.bard; + +import com.google.common.base.Preconditions; +import lombok.Getter; +import org.bukkit.scheduler.BukkitTask; + +/** + * Holds data about a {@link BardClass}. + */ +public class BardData { + + public static final double ENERGY_PER_MILLISECOND = 1.25D; + public static final double MIN_ENERGY = 0.0D; + public static final double MAX_ENERGY = 120.0D; + public static final long MAX_ENERGY_MILLIS = (long) (MAX_ENERGY * 1000L); + + @Getter + private long buffCooldown; + + @Getter + protected BukkitTask heldTask; // TODO: find a way to make private + + private long energyStart; + + public void setBuffCooldown(long millis) { + this.buffCooldown = System.currentTimeMillis() + millis; + } + + public long getRemainingBuffDelay() { + return this.buffCooldown - System.currentTimeMillis(); + } + + /** + * Begins tracking energy. + */ + public void startEnergyTracking() { + this.setEnergy(0); + } + + /** + * Gets the energy in milliseconds. + * + * @return energy in milliseconds + */ + public long getEnergyMillis() { + if (this.energyStart == 0L) { + return 0L; + } + + return Math.min(MAX_ENERGY_MILLIS, + (long) (ENERGY_PER_MILLISECOND * (System.currentTimeMillis() - this.energyStart))); + } + + public double getEnergy() { + // TODO: double check + return Math.round(this.getEnergyMillis() / 100.0) / 10.0; + } + + public void setEnergy(double energy) { + Preconditions.checkArgument(energy >= MIN_ENERGY, "Energy cannot be less than " + MIN_ENERGY); + Preconditions.checkArgument(energy <= MAX_ENERGY, "Energy cannot be more than " + MAX_ENERGY); + this.energyStart = (long) (System.currentTimeMillis() - (1000L * energy)); + } + + public Object getHeldTask() { + return this.heldTask; + } +} diff --git a/src/me/bruce/factions/armors/bard/BardEffect.java b/src/me/bruce/factions/armors/bard/BardEffect.java new file mode 100644 index 0000000..b78a0e8 --- /dev/null +++ b/src/me/bruce/factions/armors/bard/BardEffect.java @@ -0,0 +1,16 @@ +package me.bruce.factions.armors.bard; + +import org.bukkit.potion.PotionEffect; + +public class BardEffect { + + public final int energyCost; + public final PotionEffect clickable; + public final PotionEffect heldable; + + public BardEffect(int energyCost, PotionEffect clickable, PotionEffect heldable) { + this.energyCost = energyCost; + this.clickable = clickable; + this.heldable = heldable; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/bard/EffectRestorer.java b/src/me/bruce/factions/armors/bard/EffectRestorer.java new file mode 100644 index 0000000..8a8b76d --- /dev/null +++ b/src/me/bruce/factions/armors/bard/EffectRestorer.java @@ -0,0 +1,68 @@ +package me.bruce.factions.armors.bard; + +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.armors.event.PvpClassUnequipEvent; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PotionEffectExpireEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.Collection; +import java.util.UUID; + +public class EffectRestorer implements Listener { + + private final Table restores = HashBasedTable.create(); + + public EffectRestorer(LorexHCF plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPvpClassUnequip(PvpClassUnequipEvent event) { + restores.rowKeySet().remove(event.getPlayer().getUniqueId()); + } + + public void setRestoreEffect(Player player, PotionEffect effect) { + boolean shouldCancel = true; + Collection activeList = player.getActivePotionEffects(); + for (PotionEffect active : activeList) + if (active.getType().equals(effect.getType())) { + + if (effect.getAmplifier() < active.getAmplifier()) { + return; + } + if ((effect.getAmplifier() == active.getAmplifier()) && (effect.getDuration() < active.getDuration())) { + return; + } + restores.put(player.getUniqueId(), active.getType(), active); + shouldCancel = false; + break; + } + player.addPotionEffect(effect, true); + if ((shouldCancel) && (effect.getDuration() > 100) && (effect.getDuration() < PvpClass.DEFAULT_MAX_DURATION)) { + restores.remove(player.getUniqueId(), effect.getType()); + } + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPotionEffectExpire(PotionEffectExpireEvent event) { + LivingEntity livingEntity = event.getEntity(); + Player player; + PotionEffect previous; + if (((livingEntity instanceof Player)) && ((previous = restores + .remove((player = (Player) livingEntity).getUniqueId(), event.getEffect().getType())) != null)) { + event.setCancelled(true); + player.addPotionEffect(previous, true); + } + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/event/PvpClassEquipEvent.java b/src/me/bruce/factions/armors/event/PvpClassEquipEvent.java new file mode 100644 index 0000000..f2fc329 --- /dev/null +++ b/src/me/bruce/factions/armors/event/PvpClassEquipEvent.java @@ -0,0 +1,40 @@ +package me.bruce.factions.armors.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import me.bruce.factions.armors.PvpClass; + +/** + * Event called when a player equips a {@link PvpClass}. + */ +public class PvpClassEquipEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + + private final PvpClass pvpClass; + + public PvpClassEquipEvent(Player player, PvpClass pvpClass) { + super(player); + this.pvpClass = pvpClass; + } + + /** + * Gets the {@link PvpClass} being unequipped. + * + * @return the unequipped {@link PvpClass} + */ + public PvpClass getPvpClass() { + return pvpClass; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} diff --git a/src/me/bruce/factions/armors/event/PvpClassUnequipEvent.java b/src/me/bruce/factions/armors/event/PvpClassUnequipEvent.java new file mode 100644 index 0000000..bd12e2b --- /dev/null +++ b/src/me/bruce/factions/armors/event/PvpClassUnequipEvent.java @@ -0,0 +1,40 @@ +package me.bruce.factions.armors.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import me.bruce.factions.armors.PvpClass; + +/** + * Event called when a player unequips a {@link PvpClass}. + */ +public class PvpClassUnequipEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + + private final PvpClass pvpClass; + + public PvpClassUnequipEvent(Player player, PvpClass pvpClass) { + super(player); + this.pvpClass = pvpClass; + } + + /** + * Gets the {@link PvpClass} being unequipped. + * + * @return the unequipped {@link PvpClass} + */ + public PvpClass getPvpClass() { + return pvpClass; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} diff --git a/src/me/bruce/factions/armors/miner/MinerClass.java b/src/me/bruce/factions/armors/miner/MinerClass.java new file mode 100644 index 0000000..7abe0b9 --- /dev/null +++ b/src/me/bruce/factions/armors/miner/MinerClass.java @@ -0,0 +1,141 @@ +package me.bruce.factions.armors.miner; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import LorexMC.us.utils.BukkitUtils; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.armors.event.PvpClassEquipEvent; + +import java.util.concurrent.TimeUnit; + +/** + * Represents a {@link PvpClass} used to enhance mining quality. + */ +public class MinerClass extends PvpClass implements Listener { + + // The minimum height level to obtain the Invisibility effect. + private static final int INVISIBILITY_HEIGHT_LEVEL = 30; + private static final PotionEffect HEIGHT_INVISIBILITY = new PotionEffect(PotionEffectType.INVISIBILITY, + Integer.MAX_VALUE, 0); + + private final LorexHCF plugin; + + public MinerClass(LorexHCF plugin) { + super("Miner", TimeUnit.SECONDS.toMillis(10L)); + + this.plugin = plugin; + this.passiveEffects.add(new PotionEffect(PotionEffectType.FAST_DIGGING, Integer.MAX_VALUE, 1)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0)); + } + + private void removeInvisibilitySafely(Player player) { + for (PotionEffect active : player.getActivePotionEffects()) { + if (active.getType().equals(PotionEffectType.INVISIBILITY) && active.getDuration() > DEFAULT_MAX_DURATION) { + player.sendMessage(ChatColor.RED + getName() + ChatColor.GRAY + " invisibility removed."); + player.removePotionEffect(active.getType()); + break; + } + } + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerDamage(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + if (entity instanceof Player && BukkitUtils.getFinalAttacker(event, false) != null) { + Player player = (Player) entity; + if (plugin.getPvpClassManager().hasClassEquipped(player, this)) { + removeInvisibilitySafely(player); + } + } + } + + @Override + public void onUnequip(Player player) { + super.onUnequip(player); + removeInvisibilitySafely(player); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerMove(PlayerMoveEvent event) { + conformMinerInvisibility(event.getPlayer(), event.getFrom(), event.getTo()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerTeleport(PlayerTeleportEvent event) { + conformMinerInvisibility(event.getPlayer(), event.getFrom(), event.getTo()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onClassEquip(PvpClassEquipEvent event) { + Player player = event.getPlayer(); + if (event.getPvpClass() == this && player.getLocation().getBlockY() <= INVISIBILITY_HEIGHT_LEVEL) { + player.addPotionEffect(HEIGHT_INVISIBILITY, true); + player.sendMessage(ChatColor.AQUA + getName() + ChatColor.GRAY + " invisibility added."); + } + } + + /** + * Applies the {@link MinerClass} invisibility {@link PotionEffect} depending on + * the {@link Player}s {@link Location}. + * + * @param player + * the {@link Player} to apply for + * @param from + * the from {@link Location} + * @param to + * the to {@link Location} + */ + private void conformMinerInvisibility(Player player, Location from, Location to) { + int fromY = from.getBlockY(); + int toY = to.getBlockY(); + if (fromY != toY && plugin.getPvpClassManager().hasClassEquipped(player, this)) { + boolean isInvisible = player.hasPotionEffect(PotionEffectType.INVISIBILITY); + if (toY > INVISIBILITY_HEIGHT_LEVEL) { + if (fromY <= INVISIBILITY_HEIGHT_LEVEL && isInvisible) { + removeInvisibilitySafely(player); + } + } else { + if (!isInvisible) { + player.addPotionEffect(HEIGHT_INVISIBILITY, true); + player.sendMessage(ChatColor.AQUA + getName() + ChatColor.GRAY + " invisibility added."); + } + } + } + } + + @Override + public boolean isApplicableFor(Player player) { + PlayerInventory playerInventory = player.getInventory(); + + ItemStack helmet = playerInventory.getHelmet(); + if (helmet == null || helmet.getType() != Material.IRON_HELMET) + return false; + + ItemStack chestplate = playerInventory.getChestplate(); + if (chestplate == null || chestplate.getType() != Material.IRON_CHESTPLATE) + return false; + + ItemStack leggings = playerInventory.getLeggings(); + if (leggings == null || leggings.getType() != Material.IRON_LEGGINGS) + return false; + + ItemStack boots = playerInventory.getBoots(); + return !(boots == null || boots.getType() != Material.IRON_BOOTS); + } +} diff --git a/src/me/bruce/factions/armors/rogue/RogueClass.java b/src/me/bruce/factions/armors/rogue/RogueClass.java new file mode 100644 index 0000000..21600e0 --- /dev/null +++ b/src/me/bruce/factions/armors/rogue/RogueClass.java @@ -0,0 +1,84 @@ +package me.bruce.factions.armors.rogue; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.ymls.SettingsYML; + +import java.util.concurrent.TimeUnit; + +public class RogueClass extends PvpClass implements Listener { + + private final LorexHCF plugin; + + public RogueClass(LorexHCF plugin) { + super("Rogue", TimeUnit.SECONDS.toMillis(15L)); + + this.plugin = plugin; + this.passiveEffects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2)); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + Entity damager = event.getDamager(); + if (entity instanceof Player && damager instanceof Player) { + Player attacker = (Player) damager; + if (plugin.getPvpClassManager().getEquippedClass(attacker) == this) { + ItemStack stack = attacker.getItemInHand(); + if (stack != null && stack.getType() == Material.GOLD_SWORD && stack.getEnchantments().isEmpty()) { + Player player = (Player) entity; + player.sendMessage( + SettingsYML.ENEMY_COLOUR + attacker.getName() + ChatColor.YELLOW + " has backstabbed you."); + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); + + attacker.sendMessage(ChatColor.YELLOW + "You have backstabbed " + SettingsYML.ENEMY_COLOUR + + player.getName() + ChatColor.YELLOW + '.'); + attacker.setItemInHand(new ItemStack(Material.AIR, 1)); + player.setHealth(12); + attacker.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); + + event.setDamage(3.0); + } + } + } + } + + @Override + public boolean isApplicableFor(Player player) { + PlayerInventory playerInventory = player.getInventory(); + + ItemStack helmet = playerInventory.getHelmet(); + if (helmet == null || helmet.getType() != Material.CHAINMAIL_HELMET) { + return false; + } + + ItemStack chestplate = playerInventory.getChestplate(); + if (chestplate == null || chestplate.getType() != Material.CHAINMAIL_CHESTPLATE) { + return false; + } + + ItemStack leggings = playerInventory.getLeggings(); + if (leggings == null || leggings.getType() != Material.CHAINMAIL_LEGGINGS) { + return false; + } + + ItemStack boots = playerInventory.getBoots(); + return !(boots == null || boots.getType() != Material.CHAINMAIL_BOOTS); + } +} diff --git a/src/me/bruce/factions/commands/.DS_Store b/src/me/bruce/factions/commands/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9b925a96a539d0616f41eca4be31d5f03e36942c GIT binary patch literal 6148 zcmeHKO;5ux41F0p3~`w_am+8E;vZC_2o8t?h&!d@L%=@NcI?`p&a)j2O#^A-FlorH z;+HzM)4Wu510akR<1=6gV8ABWJEZzSWL(;Y^pZs|XpRY${ShGb2M~1GQ0cXG&STP{qhsY+FC+rOM(?O+20AinJ753#UAu%yw zp0G3I2qjo3(LzHyVgw7PJtn_AVP|OJ2s$(Kq?toHp#+_s_NeX%xuI)kz!_L);J|K& zQvWZ0KmV@>`JFT14E!qwLch2xMqE;=ts9GzS{vCO*hIvyGhBtRqotU>Qi@O5RA`UV VA?67?Ls}^QBcL?6at3zFz!!`kLzVyl literal 0 HcmV?d00001 diff --git a/src/me/bruce/factions/commands/BallerRevive.java b/src/me/bruce/factions/commands/BallerRevive.java new file mode 100644 index 0000000..64fdccd --- /dev/null +++ b/src/me/bruce/factions/commands/BallerRevive.java @@ -0,0 +1,63 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class BallerRevive implements CommandExecutor { + + private final LorexHCF plugin; + + public BallerRevive(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lBaller Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} diff --git a/src/me/bruce/factions/commands/BanCommand.java b/src/me/bruce/factions/commands/BanCommand.java new file mode 100644 index 0000000..444a9c9 --- /dev/null +++ b/src/me/bruce/factions/commands/BanCommand.java @@ -0,0 +1,34 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class BanCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!(sender instanceof Player)) { + return true; + } + if(args.length == 0) { + sender.sendMessage("usage /ban "); + return true; + } + Player target = Bukkit.getPlayer(args[0]); + Player p = (Player) sender; + if(target == null) { + sender.sendMessage("ERROR"); + return true; + } + target.kickPlayer(ChatColor.RED + "you have beened banned"); + target.setBanned(true); + return true; + } + + + +} diff --git a/src/me/bruce/factions/commands/BroadCastCommand.java b/src/me/bruce/factions/commands/BroadCastCommand.java new file mode 100644 index 0000000..2d13260 --- /dev/null +++ b/src/me/bruce/factions/commands/BroadCastCommand.java @@ -0,0 +1,35 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class BroadCastCommand implements CommandExecutor{ + + public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) { + if (cmd.getName().equalsIgnoreCase("broadcast")) { + String r = ""; + if (sender.hasPermission("command.broadcast")) { + if (args.length > 0) { + for (int i = 0; i < args.length; ++i) { + r = String.valueOf(r) + args[i] + " "; + } + r = r.replace("&", "§"); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4Alert&8]&f " + r)); + } + else { + sender.sendMessage(ChatColor.RED + "Usage: /broadcast "); + } + } + else { + sender.sendMessage("§cYou lack the sufficient permissions to execute this command."); + } + } + return true; + } +} + + + diff --git a/src/me/bruce/factions/commands/Buy.java b/src/me/bruce/factions/commands/Buy.java new file mode 100644 index 0000000..d47af4f --- /dev/null +++ b/src/me/bruce/factions/commands/Buy.java @@ -0,0 +1,22 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Buy implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!(sender instanceof Player)) { + sender.sendMessage("Cannot use this command in console"); + return true; + } + sender.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + " www.zorex.us"); + return true; + } +} + + diff --git a/src/me/bruce/factions/commands/CobbleCommand.java b/src/me/bruce/factions/commands/CobbleCommand.java new file mode 100644 index 0000000..52d475b --- /dev/null +++ b/src/me/bruce/factions/commands/CobbleCommand.java @@ -0,0 +1,56 @@ +package me.bruce.factions.commands; + +import java.util.Set; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.google.common.collect.Sets; + +public class CobbleCommand implements Listener, CommandExecutor { + + public static Set disabled = Sets.newHashSet(); + + @Override + public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) { + + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can focus."); + return true; + } + Player player = (Player) sender; + if (disabled.contains(player)) { + disabled.remove(player); + player.sendMessage(ChatColor.GRAY + " § " + ChatColor.YELLOW + "You have " + ChatColor.RED + "disabled " + + ChatColor.YELLOW + "Cobblestone and Stone pickup!"); + } else { + disabled.add(player); + player.sendMessage(ChatColor.GRAY + " § " + ChatColor.YELLOW + "You have " + ChatColor.GREEN + "enabled " + + ChatColor.YELLOW + "Cobblestone and Stone pickup!"); + } + return true; + } + + @EventHandler + public void onPlayerPickup(PlayerQuitEvent event) { + disabled.remove(event.getPlayer()); + } + + @EventHandler + public void onPlayerPickup(PlayerPickupItemEvent event) { + Material type = event.getItem().getItemStack().getType(); + if (type == Material.STONE || type == Material.COBBLESTONE) { + if (disabled.contains(event.getPlayer())) { + event.setCancelled(true); + } + } + } +} diff --git a/src/me/bruce/factions/commands/CoordsCommand.java b/src/me/bruce/factions/commands/CoordsCommand.java new file mode 100644 index 0000000..163209b --- /dev/null +++ b/src/me/bruce/factions/commands/CoordsCommand.java @@ -0,0 +1,33 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +public class CoordsCommand implements CommandExecutor, TabCompleter { + + @Override + public boolean onCommand(CommandSender p, Command command, String label, String[] args) { + if (!(p instanceof Player)) { + p.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + p.sendMessage(""); + p.sendMessage("§7§m---------------------------------------------------"); + p.sendMessage("§7§m---------------------------------------------------"); + p.sendMessage(""); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/Discord.java b/src/me/bruce/factions/commands/Discord.java new file mode 100644 index 0000000..72a1add --- /dev/null +++ b/src/me/bruce/factions/commands/Discord.java @@ -0,0 +1,5 @@ +package me.bruce.factions.commands; + +public class Discord { + +} diff --git a/src/me/bruce/factions/commands/FRCOMMAND.java b/src/me/bruce/factions/commands/FRCOMMAND.java new file mode 100644 index 0000000..b5302ac --- /dev/null +++ b/src/me/bruce/factions/commands/FRCOMMAND.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class FRCOMMAND implements Listener, CommandExecutor{ + public static ArrayList fr = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!fr.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7fire resistance.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0)); + fr.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisbaled &7fire resistance.")); + p.removePotionEffect(PotionEffectType.FIRE_RESISTANCE); + fr.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/FixCommand.java b/src/me/bruce/factions/commands/FixCommand.java new file mode 100644 index 0000000..52703f9 --- /dev/null +++ b/src/me/bruce/factions/commands/FixCommand.java @@ -0,0 +1,57 @@ +package me.bruce.factions.commands; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import LorexMC.us.utils.internal.com.bruce.base.BasePlugin; + +public class FixCommand implements CommandExecutor{ + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + Player target; + if (args.length > 0) { + target = BukkitUtils.playerWithNameOrUUID(args[0]); + } + else { + if (!(sender instanceof Player)) { + sender.sendMessage("Cannot use in console"); + return true; + } + target = (Player)sender; + } + if (target == null) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[0])); + return true; + } + final Set toRepair = new HashSet(); + if (args.length >= 1 && args[1].equalsIgnoreCase("all")) { + final PlayerInventory targetInventory = target.getInventory(); + toRepair.addAll(Arrays.asList(targetInventory.getContents())); + toRepair.addAll(Arrays.asList(targetInventory.getArmorContents())); + } + else { + toRepair.add(target.getItemInHand()); + } + for (final ItemStack stack : toRepair) { + if (stack != null && stack.getType() != Material.AIR) { + stack.setDurability((short)0); + } + } + sender.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + "Repaired " + ((toRepair.size() > 1) ? "all" : "item in hand") + " of " + target.getName() + '.'); + return true; + } + +} diff --git a/src/me/bruce/factions/commands/Forums.java b/src/me/bruce/factions/commands/Forums.java new file mode 100644 index 0000000..47e8cef --- /dev/null +++ b/src/me/bruce/factions/commands/Forums.java @@ -0,0 +1,5 @@ +package me.bruce.factions.commands; + +public class Forums { + +} diff --git a/src/me/bruce/factions/commands/FreezeCommand.java b/src/me/bruce/factions/commands/FreezeCommand.java new file mode 100644 index 0000000..efde9ba --- /dev/null +++ b/src/me/bruce/factions/commands/FreezeCommand.java @@ -0,0 +1,229 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.other.chat.ClickAction; +import LorexMC.us.utils.other.chat.Text; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.event.PlayerFreezeEvent; +import net.minecraft.util.gnu.trove.map.TObjectLongMap; +import net.minecraft.util.gnu.trove.map.hash.TObjectLongHashMap; +import net.minecraft.util.org.apache.commons.lang3.StringUtils; +import net.minecraft.util.org.apache.commons.lang3.time.DurationFormatUtils; + +public class FreezeCommand implements CommandExecutor, Listener { + private static final String FREEZE_BYPASS = "command.freeze.bypass"; + public static TObjectLongMap frozenPlayers; + public static HashMap frozenReasons; + private long defaultFreezeDuration; + private long serverFrozenMillis; + public static HashSet frozen; + + static { + FreezeCommand.frozenPlayers = new TObjectLongHashMap(); + FreezeCommand.frozenReasons = new HashMap(); + } + + public FreezeCommand(final LorexHCF plugin) { + FreezeCommand.frozen = new HashSet(); + this.defaultFreezeDuration = TimeUnit.MINUTES.toMillis(60L); + Bukkit.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + sender.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + "Usage: " + "/freeze "); + return true; + } + final String reason = null; + Long freezeTicks = this.defaultFreezeDuration; + final long millis = System.currentTimeMillis(); + if (args[0].equalsIgnoreCase("all") && sender.hasPermission(String.valueOf(command.getPermission()) + ".all")) { + final long oldTicks = this.getRemainingServerFrozenMillis(); + if (oldTicks > 0L) { + freezeTicks = 0L; + } + this.serverFrozenMillis = millis + this.defaultFreezeDuration; + Bukkit.getServer() + .broadcastMessage(ChatColor.YELLOW + "The server is " + ((freezeTicks > 0L) + ? ("now frozen for " + DurationFormatUtils.formatDurationWords(freezeTicks, true, true)) + : "no longer frozen") + ((reason == null) ? "" : (" with reason " + reason)) + '.'); + return true; + } + final Player target = Bukkit.getServer().getPlayer(args[0]); + if (target == null) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[0] + ChatColor.GOLD + "' not found."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final boolean shouldFreeze = this.getRemainingPlayerFrozenMillis(targetUUID) > 0L; + final PlayerFreezeEvent playerFreezeEvent = new PlayerFreezeEvent(target, shouldFreeze); + Bukkit.getServer().getPluginManager().callEvent(playerFreezeEvent); + if (playerFreezeEvent.isCancelled()) { + sender.sendMessage(ChatColor.RED + "Unable to freeze " + target.getName() + '.'); + return false; + } + if (shouldFreeze) { + FreezeCommand.frozen.remove(target.getName()); + FreezeCommand.frozenPlayers.remove(targetUUID); + sender.sendMessage(ChatColor.GOLD + "âš  " + ChatColor.LIGHT_PURPLE + target.getName() + ChatColor.YELLOW + " has been un-frozen by " + ChatColor.LIGHT_PURPLE + sender.getName()); + target.sendMessage(ChatColor.RED + "You have been un-frozen."); + target.removePotionEffect(PotionEffectType.BLINDNESS); + FreezeCommand.frozenReasons.remove(target); + } else if (args.length == 1) { + FreezeCommand.frozen.add(target.getName()); + FreezeCommand.frozenPlayers.put(targetUUID, millis + freezeTicks); + final String timeString = DurationFormatUtils.formatDurationWords(freezeTicks, true, true); + this.Message(target.getName()); + sender.sendMessage(ChatColor.GOLD + "âš  " + ChatColor.LIGHT_PURPLE + target.getName() + ChatColor.YELLOW + " has been frozen by " + ChatColor.LIGHT_PURPLE + sender.getName()); + } else { + FreezeCommand.frozen.add(target.getName()); + FreezeCommand.frozenPlayers.put(targetUUID, millis + freezeTicks); + final String timeString = DurationFormatUtils.formatDurationWords(freezeTicks, true, true); + this.Message(target.getName()); + sender.sendMessage(ChatColor.GOLD + "âš  " + ChatColor.LIGHT_PURPLE + target.getName() + ChatColor.YELLOW + " has been frozen by " + ChatColor.LIGHT_PURPLE + sender.getName()); + final String reason2 = StringUtils.join(args, ' ', 1, args.length); + FreezeCommand.frozenReasons.put(target, reason2); + } + return true; + } + + private void Message(final String name) { + final HashMap timer = new HashMap(); + final Player p = Bukkit.getPlayer(name); + final BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (FreezeCommand.frozen.contains(name)) { + p.sendMessage(" "); + p.sendMessage("§f\u2588\u2588\u2588\u2588§c\u2588§f\u2588\u2588\u2588\u2588"); + p.sendMessage("§f\u2588\u2588\u2588§c\u2588§6\u2588§c\u2588§f\u2588\u2588\u2588"); + p.sendMessage( + "§f\u2588\u2588§c\u2588§6\u2588§0\u2588§6\u2588§c\u2588§f\u2588\u2588 §4§lDo NOT log out!"); + p.sendMessage( + "§f\u2588\u2588§c\u2588§6\u2588§0\u2588§6\u2588§c\u2588§f\u2588\u2588 §cIf you do, you will be banned!"); + p.sendMessage( + "§f\u2588§c\u2588§6\u2588\u2588§0\u2588§6\u2588\u2588§c\u2588§f\u2588 §ePlease download §eTeamspeak §eand connect to:"); + p.sendMessage( + "§f\u2588§c\u2588§6\u2588\u2588\u2588\u2588\u2588§c\u2588§f\u2588 " + "§ets.Zorex.us"); + p.sendMessage("§c\u2588§6\u2588\u2588\u2588§0\u2588§6\u2588\u2588\u2588§c\u2588"); + p.sendMessage("§c\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"); + p.sendMessage(" "); + } else { + this.cancel(); + } + } + }.runTaskTimerAsynchronously(LorexHCF.getInstance(), 0L, 200L); + } + + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + return (args.length == 1) ? null : Collections.emptyList(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityDamageByEntity(final EntityDamageByEntityEvent event) { + final Entity entity = event.getEntity(); + if (entity instanceof Player) { + final Player attacker = BukkitUtils.getFinalAttacker(event, false); + if (attacker == null) { + return; + } + final Player player = (Player) entity; + if ((this.getRemainingServerFrozenMillis() > 0L + || this.getRemainingPlayerFrozenMillis(player.getUniqueId()) > 0L) + && !player.hasPermission("command.freeze.bypass")) { + attacker.sendMessage(ChatColor.RED + player.getName() + " is currently frozen, you may not attack."); + event.setCancelled(true); + return; + } + if ((this.getRemainingServerFrozenMillis() > 0L + || this.getRemainingPlayerFrozenMillis(attacker.getUniqueId()) > 0L) + && !attacker.hasPermission("command.freeze.bypass")) { + event.setCancelled(true); + attacker.sendMessage(ChatColor.RED + "You may not attack players whilst frozen."); + } + } + } + + + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onPlayerMove(final PlayerMoveEvent event) { + final Location from = event.getFrom(); + final Location to = event.getTo(); + if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ()) { + return; + } + final Player player = event.getPlayer(); + if ((this.getRemainingServerFrozenMillis() > 0L + || this.getRemainingPlayerFrozenMillis(player.getUniqueId()) > 0L) + && !player.hasPermission("command.freeze.bypass")) { + event.setTo(event.getFrom()); + } + } + + @EventHandler + public void onPlayerQuit(final PlayerQuitEvent e) { + if (FreezeCommand.frozen.contains(e.getPlayer().getUniqueId())) { + for (final Player online : Bukkit.getOnlinePlayers()) { + if (online.hasPermission("command.freeze")) { + online.sendMessage(""); + online.sendMessage(""); + online.sendMessage(""); + new Text(ChatColor.WHITE + e.getPlayer().getName() + " has " + ChatColor.DARK_RED + "QUIT" + + ChatColor.WHITE + " while frozen. " + ChatColor.GRAY + ChatColor.ITALIC + + "(Click here to ban)") + .setHoverText(ChatColor.WHITE + "Click here to permanently ban" + ChatColor.GRAY + + e.getPlayer().getName()) + .setClick(ClickAction.RUN_COMMAND, + "/ban" + e.getPlayer().getName() + "Refusal to SS | Logout") + .setColor(ChatColor.GRAY).send(online); + online.sendMessage(""); + online.sendMessage(""); + online.sendMessage(""); + } + } + } + } + + public long getRemainingServerFrozenMillis() { + return this.serverFrozenMillis - System.currentTimeMillis(); + } + + public long getRemainingPlayerFrozenMillis(final UUID uuid) { + final long remaining = FreezeCommand.frozenPlayers.get(uuid); + if (remaining == FreezeCommand.frozenPlayers.getNoEntryValue()) { + return 0L; + } + return remaining - System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/GiveCrowbarCommand.java b/src/me/bruce/factions/commands/GiveCrowbarCommand.java new file mode 100644 index 0000000..a6ef023 --- /dev/null +++ b/src/me/bruce/factions/commands/GiveCrowbarCommand.java @@ -0,0 +1,37 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import me.bruce.factions.listener.Crowbar; + +public class GiveCrowbarCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player p = (Player) sender; + if (cmd.getName().equalsIgnoreCase("crowgive")) { + if (args.length == 0) { + p.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + Player target = Bukkit.getServer().getPlayer(args[0]); + if (target == null) { + p.sendMessage(ChatColor.RED + "That player is not online!"); + return true; + } + + ItemStack stack = new Crowbar().getItemIfPresent(); + target.getInventory().addItem(new ItemStack[] { stack }); + target.sendMessage(ChatColor.GREEN + "You were given a crowbar from " + sender.getName()); + p.sendMessage(ChatColor.GREEN + "You have given " + target.getName() + " a crowbar"); + return true; + } + return false; + } +} diff --git a/src/me/bruce/factions/commands/GlowstoneMountain.java b/src/me/bruce/factions/commands/GlowstoneMountain.java new file mode 100644 index 0000000..1687830 --- /dev/null +++ b/src/me/bruce/factions/commands/GlowstoneMountain.java @@ -0,0 +1,28 @@ +package me.bruce.factions.commands; + +import org.bukkit.command.*; + +import me.bruce.factions.*; + +import org.bukkit.*; + +public class GlowstoneMountain implements CommandExecutor { + private LorexHCF hcf; + + public GlowstoneMountain(final LorexHCF hcf) { + this.hcf = hcf; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (!sender.hasPermission("command.glowstonemountain")) { + sender.sendMessage(ChatColor.RED + "You don not have permission for this command."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.YELLOW + "You have reset Glowstone Mountain!"); + // this.hcf.resetGlowstoneMountain(); + } + return true; + } +} diff --git a/src/me/bruce/factions/commands/GoppleCommand.java b/src/me/bruce/factions/commands/GoppleCommand.java new file mode 100644 index 0000000..30be702 --- /dev/null +++ b/src/me/bruce/factions/commands/GoppleCommand.java @@ -0,0 +1,57 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.DurationFormatter; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.timer.PlayerTimer; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to check remaining Notch Apple cooldown time for {@link Player}. + */ +public class GoppleCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public GoppleCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + + PlayerTimer timer = plugin.getTimerManager().getGappleTimer(); + long remaining = timer.getRemaining(player); + + if (remaining <= 0L) { + sender.sendMessage(ChatColor.RED + "Your " + timer.getDisplayName() + ChatColor.RED + + " timer is currently not active."); + return true; + } + + sender.sendMessage(ChatColor.YELLOW + "Your " + timer.getDisplayName() + ChatColor.YELLOW + + " timer is active for another " + ChatColor.BOLD + + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.YELLOW + '.'); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/HelpCommand.java b/src/me/bruce/factions/commands/HelpCommand.java new file mode 100644 index 0000000..1d4472c --- /dev/null +++ b/src/me/bruce/factions/commands/HelpCommand.java @@ -0,0 +1,76 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import me.bruce.factions.ymls.SettingsYML; + +import java.util.Collections; +import java.util.List; + +/** + * + */ +public class HelpCommand implements CommandExecutor, TabCompleter { + + @Override + public boolean onCommand(CommandSender p, Command command, String label, String[] args) { + if (!(p instanceof Player)) { + p.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if(SettingsYML.KIT_MAP == true) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &C(KitMap)")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LInformation")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWorld Border &71500 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWarzone Radius &7150 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eKits &7Diamond, Bard, Archer, Builder")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eEnd Exit &c( 150 ) South Road")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LUseful Commands")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/helpop &7Request staff assistance")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/coords &7View KOTH, Conquest and Mountain locations")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/mapkit &7Get the kit of the map")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LLinks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWebsite &7www.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eTeamspeak &7ts.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eStore &7store.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lTribes &C(Map 1)")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LInformation")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWorld Border &73000 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWarzone Radius &7800 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eKits &7Diamond, Bard, Archer, Builder")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eEnd Exit &c( 150 ) South Road")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LUseful Commands")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/helpop &7Request staff assistance")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/coords &7View KOTH, Conquest and Mountain locations")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/mapkit &7Get the kit of the map")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LLinks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWebsite &7www.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eTeamspeak &7ts.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eStore &7store.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/HubCommand.java b/src/me/bruce/factions/commands/HubCommand.java new file mode 100644 index 0000000..5592964 --- /dev/null +++ b/src/me/bruce/factions/commands/HubCommand.java @@ -0,0 +1,57 @@ +package me.bruce.factions.commands; + +import java.io.DataOutputStream; +import java.io.IOException; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import net.minecraft.util.org.apache.commons.io.output.ByteArrayOutputStream; + +public class HubCommand implements CommandExecutor { + + private final LorexHCF plugin; + + public HubCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + public static void teleport(Player pl, String input) { + ByteArrayOutputStream b = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(b); + try { + out.writeUTF("Connect"); + out.writeUTF(input); + } catch (IOException localIOException) { + } + pl.sendPluginMessage(LorexHCF.getInstance(), "BungeeCord", b.toByteArray()); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "We are sending you to The Hub."); + teleport(p, "hub"); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(LorexHCF.getInstance(), new Runnable() { + @Override + public void run() { + if (p.isOnline()) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&cWe couldn't connect you to any of the Hubs, please try again later.")); + } + } + }, 20 * 5); + return true; + } + +} diff --git a/src/me/bruce/factions/commands/InveeSeeCommand.java b/src/me/bruce/factions/commands/InveeSeeCommand.java new file mode 100644 index 0000000..043fedc --- /dev/null +++ b/src/me/bruce/factions/commands/InveeSeeCommand.java @@ -0,0 +1,122 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import me.bruce.factions.LorexHCF; + +public class InveeSeeCommand implements Listener,CommandExecutor { + private InventoryType[] types; + private Map inventories; + + public void InvSeeCommand(final LorexHCF plugin) { + this.types = new InventoryType[] { InventoryType.BREWING, InventoryType.CHEST, InventoryType.DISPENSER, InventoryType.ENCHANTING, InventoryType.FURNACE, InventoryType.HOPPER, InventoryType.PLAYER, InventoryType.WORKBENCH }; + this.inventories = new EnumMap(InventoryType.class); + Bukkit.getPluginManager().registerEvents((Listener)this, (Plugin)plugin); + } + + public boolean isPlayerOnlyCommand() { + return true; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /invsee "); + return true; + } + final Player target = BukkitUtils.playerWithNameOrUUID(args[0]); + if (target == null) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[0])); + return true; + } + sender.sendMessage(ChatColor.GRAY + "This players inventory contains: "); + ItemStack[] arrayOfItemStack; + for (int j = (arrayOfItemStack = target.getInventory().getContents()).length, i = 0; i < j; ++i) { + final ItemStack items = arrayOfItemStack[i]; + if (items != null) { + sender.sendMessage(ChatColor.AQUA + items.getType().toString().replace("_", "").toLowerCase() + ": " + items.getAmount()); + } + } + return true; + } + else { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /invsee "); + return true; + } + final Player player = (Player)sender; + Inventory inventory = null; + final InventoryType[] types = this.types; + final int length = types.length; + int k = 0; + while (k < length) { + final InventoryType type = types[k]; + if (type.name().equalsIgnoreCase(args[0])) { + final Inventory inventoryRevert; + inventory = inventories.putIfAbsent(type, inventoryRevert = Bukkit.createInventory((InventoryHolder)player, type)); + if (inventory != null) { + break; + } + inventory = inventoryRevert; + break; + } + else { + ++k; + } + } + if (inventory == null) { + final Player target2 = BukkitUtils.playerWithNameOrUUID(args[0]); + if (sender.equals(target2)) { + sender.sendMessage(ChatColor.RED + "You cannot check the inventory of yourself."); + return true; + } + if (target2 == null) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[0])); + return true; + } + inventory = (Inventory)target2.getInventory(); + } + player.openInventory(inventory); + return true; + } + } + + public List onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { + if (args.length != 1) { + return Collections.emptyList(); + } + final InventoryType[] values = InventoryType.values(); + final List results = new ArrayList(values.length); + final Player senderPlayer = (Player)sender; + Player[] arrayOfPlayer; + for (int j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).length, i = 0; i < j; ++i) { + final Player target = arrayOfPlayer[i]; + if (senderPlayer == null || senderPlayer.canSee(target)) { + results.add(target.getName()); + } + } + return BukkitUtils.getCompletions(args, results); + } + } + + + diff --git a/src/me/bruce/factions/commands/LFFCommand.java b/src/me/bruce/factions/commands/LFFCommand.java new file mode 100644 index 0000000..4057cf2 --- /dev/null +++ b/src/me/bruce/factions/commands/LFFCommand.java @@ -0,0 +1,50 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.internal.com.bruce.base.BasePlugin; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.struct.Relation; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.listener.Cooldowns; + +public class LFFCommand implements CommandExecutor { + + private final LorexHCF plugin; + + public LFFCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + final PlayerFaction faction = LorexHCF.getInstance().getFactionManager().getPlayerFaction(p); + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This is a player only command"); + return true; + } + if (Cooldowns.isOnCooldown("lff_cooldown", p)) { + p.sendMessage("§cYou Still have a cooldown"); + return true; + } + if(faction != null) { + sender.sendMessage("§cYou are already in a faction"); + return true; + } + if (sender instanceof Player) { + final Player player = (Player) sender; + Bukkit.broadcastMessage(ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH.toString() + "--------------------------------"); + Bukkit.broadcastMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + sender.getName() + ChatColor.GRAY + " is looking for a faction!"); + Bukkit.broadcastMessage(ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH.toString() + "--------------------------------"); + Cooldowns.addCooldown("lff_cooldown", p, 900); + } + return true; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/LogoutCommand.java b/src/me/bruce/factions/commands/LogoutCommand.java new file mode 100644 index 0000000..f1e6fa8 --- /dev/null +++ b/src/me/bruce/factions/commands/LogoutCommand.java @@ -0,0 +1,49 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.timer.type.LogoutTimer; + +import java.util.Collections; +import java.util.List; + +public class LogoutCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public LogoutCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + LogoutTimer logoutTimer = plugin.getTimerManager().getLogoutTimer(); + + if (!logoutTimer.setCooldown(player, player.getUniqueId())) { + sender.sendMessage(ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + + " timer is already active."); + return true; + } + + sender.sendMessage( + ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + " timer has started."); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/MapKitCommand.java b/src/me/bruce/factions/commands/MapKitCommand.java new file mode 100644 index 0000000..327baf1 --- /dev/null +++ b/src/me/bruce/factions/commands/MapKitCommand.java @@ -0,0 +1,82 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.WordUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionType; + +import LorexMC.us.utils.InventoryUtils; +import LorexMC.us.utils.ItemBuilder; +import LorexMC.us.utils.other.chat.Lang; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.ymls.SettingsYML; + +public class MapKitCommand implements CommandExecutor, TabCompleter, Listener { + private final Set tracking = new HashSet(); + + public MapKitCommand(LorexHCF plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + List items = new ArrayList(); + for (Map.Entry entry : SettingsYML.ENCHANTMENT_LIMITS.entrySet()) { + items.add(new ItemBuilder(Material.ENCHANTED_BOOK).displayName( + ChatColor.YELLOW + Lang.fromEnchantment(entry.getKey()) + ": " + ChatColor.GREEN + entry.getValue()) + .build()); + } + for (Map.Entry entry : SettingsYML.POTION_LIMITS.entrySet()) { + items.add(new ItemBuilder(new Potion(entry.getKey()).toItemStack(1)) + .displayName(ChatColor.YELLOW + WordUtils.capitalizeFully(entry.getKey().name().replace('_', ' ')) + + ": " + ChatColor.GREEN + entry.getValue()) + .build()); + } + Player player = (Player) sender; + Inventory inventory = Bukkit.createInventory(player, InventoryUtils.getSafestInventorySize(items.size()), + "Zorex MapKit"); + this.tracking.add(inventory); + for (ItemStack item : items) { + inventory.addItem(new ItemStack[] { item }); + } + player.openInventory(inventory); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onInventoryClick(InventoryClickEvent event) { + if (this.tracking.contains(event.getInventory())) { + event.setCancelled(true); + } + } +} diff --git a/src/me/bruce/factions/commands/MedicCommand.java b/src/me/bruce/factions/commands/MedicCommand.java new file mode 100644 index 0000000..8b1379e --- /dev/null +++ b/src/me/bruce/factions/commands/MedicCommand.java @@ -0,0 +1,95 @@ +package me.bruce.factions.commands; + +import java.util.*; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.faction.struct.Relation; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.listener.Cooldowns; + +public class MedicCommand implements CommandExecutor { + private final LorexHCF plugin; + + public MedicCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + public String getUsage(final String label) { + return String.valueOf('/') + label + ' ' + "revive "; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + final Player p = (Player) sender; + if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Usage: " + this.getUsage(label)); + return true; + } + if (Cooldowns.isOnCooldown("medic_cooldown", p)) { + p.sendMessage(ChatColor.RED + "You still have a " + ChatColor.DARK_GRAY + ChatColor.BOLD + "Amethyst" + + ChatColor.RED + " cooldown for another " + + (Cooldowns.getCooldownForPlayerLong("medic_cooldown", p)) + ChatColor.RED + '.'); + return true; + } + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not online."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + Relation relation = Relation.ENEMY; + if (sender instanceof Player) { + final Player player = (Player) sender; + final UUID playerUUID = player.getUniqueId(); + final int selfLives = this.plugin.getDeathbanManager().getLives(playerUUID); + Cooldowns.addCooldown("medic_cooldown", p, 5400); + final PlayerFaction playerFaction = this.plugin.getFactionManager().getPlayerFaction(player); + relation = ((playerFaction == null) ? Relation.ENEMY + : playerFaction.getFactionRelation(this.plugin.getFactionManager().getPlayerFaction(targetUUID))); + sender.sendMessage(ChatColor.YELLOW + "You have revived " + relation.toChatColour() + target.getName() + + ChatColor.YELLOW + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&8&l" + p.getName().toUpperCase() + + " &7has used their Amethyst Rank &eto revive &8&l" + target.getName().toUpperCase() + "&7.")); + } + factionTarget.removeDeathban(); + return true; + } + + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length != 2) { + return Collections.emptyList(); + } + final List results = new ArrayList(); + final Collection factionUsers = this.plugin.getUserManager().getUsers().values(); + for (final FactionUser factionUser : factionUsers) { + final Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + final String offlineName = offlinePlayer.getName(); + if (offlineName == null) { + continue; + } + results.add(offlinePlayer.getName()); + } + } + return results; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/OresCommand.java b/src/me/bruce/factions/commands/OresCommand.java new file mode 100644 index 0000000..4d6aeff --- /dev/null +++ b/src/me/bruce/factions/commands/OresCommand.java @@ -0,0 +1,96 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; + +public class OresCommand implements CommandExecutor { + + private LorexHCF hcf; + + public OresCommand(LorexHCF hcf) { + this.hcf = hcf; + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can use this command!"); + return true; + } + if (args.length > 1) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + Player p = (Player) sender; + if (args.length == 0) { + String uuid = p.getUniqueId().toString(); + if (hcf.getConfig().contains(uuid)) { + p.sendMessage( + ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "------------------------------------"); + p.sendMessage(ChatColor.YELLOW + "Your Ores:"); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + ChatColor.BOLD + + "Stone: " + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Stone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.DARK_GRAY + "Coal: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Coal")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.BLUE + "Lapis: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Lapis")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.RED + "Redstone: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Redstone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + "Iron: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Iron")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GOLD + "Gold: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Gold")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.AQUA + "Diamond: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Diamond")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GREEN + "Emeraid: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Emerald")); + p.sendMessage( + ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "------------------------------------"); + } else { + p.sendMessage(ChatColor.RED + "You haven't mined anything yet!"); + } + } else { + if (args.length == 1) { + Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + target = (Player) Bukkit.getOfflinePlayer(args[0]); + } + String uuid = target.getUniqueId().toString(); + if (hcf.getConfig().contains(uuid)) { + p.sendMessage(ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + + "------------------------------------"); + p.sendMessage(ChatColor.YELLOW + target.getName() + "'s Ores:"); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + ChatColor.BOLD + + "Stone: " + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Stone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.DARK_GRAY + "Coal: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Coal")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.BLUE + "Lapis: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Lapis")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.RED + "Redstone: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Redstone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + "Iron: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Iron")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GOLD + "Gold: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Gold")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.AQUA + "Diamond: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Diamond")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GREEN + "Emeraid: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Emerald")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY.toString() + + ChatColor.STRIKETHROUGH + "------------------------------------"); + } else { + p.sendMessage(ChatColor.RED + target.getName() + " hasn't mined anything yet!"); + } + } + } + return true; + } + +} diff --git a/src/me/bruce/factions/commands/Panic.java b/src/me/bruce/factions/commands/Panic.java new file mode 100644 index 0000000..e879fa8 --- /dev/null +++ b/src/me/bruce/factions/commands/Panic.java @@ -0,0 +1,41 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.md_5.bungee.api.ChatColor; + +public class Panic implements CommandExecutor{ + ArrayList panic = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!(sender instanceof Player)) { + sender.sendMessage("Cannot use in console..."); + } + Player p = (Player) sender; + for(Player staff : Bukkit.getOnlinePlayers()) { + if(!panic.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.RED + "You Have used your panic!"); + staff.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&3&lPANIC&8] " + ChatColor.RED + sender.getName() + " &7Has used there panic ")); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ss " + sender.getName()); + panic.add(p.getUniqueId()); + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&3&lPANIC&8] " + " &7You have unpaniced. ")); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ss " + p.getName()); + panic.remove(p.getUniqueId()); + } + } + return true; + } +} + + + diff --git a/src/me/bruce/factions/commands/PingCommand.java b/src/me/bruce/factions/commands/PingCommand.java new file mode 100644 index 0000000..636cc3b --- /dev/null +++ b/src/me/bruce/factions/commands/PingCommand.java @@ -0,0 +1,32 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; + +public class PingCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player target = (Player) sender; + if(target.getPing() < 50) { + sender.sendMessage((target.equals(sender) ? (ChatColor.GREEN + "Your current ping is ") + : (ChatColor.GRAY + "Ping of §c" + (target.getName() + " §7is §c"))) + target.getPing()); + return true; + } + if(target.getPing() > 50){ + target.sendMessage("§cWarning Your ping is to high."); + return true; + } + return true; + } + +} diff --git a/src/me/bruce/factions/commands/PlayTimeCommand.java b/src/me/bruce/factions/commands/PlayTimeCommand.java new file mode 100644 index 0000000..62504c9 --- /dev/null +++ b/src/me/bruce/factions/commands/PlayTimeCommand.java @@ -0,0 +1,47 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang.time.DurationFormatUtils; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import me.bruce.factions.LorexHCF; + +public class PlayTimeCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + OfflinePlayer target; + if (args.length >= 1) { + target = BukkitUtils.offlinePlayerWithNameOrUUID(args[0]); + } else { + if (!(sender instanceof Player)) { + sender.sendMessage("You can only use this if you are a player!"); + return true; + } + target = (OfflinePlayer) sender; + } + if ((!target.hasPlayedBefore()) && (!target.isOnline())) { + sender.sendMessage( + String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, new Object[] { args[0] })); + return true; + } + sender.sendMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + target.getName() + ChatColor.GRAY + + " has been playing Zorex for " + ChatColor.GREEN + + DurationFormatUtils.formatDurationWords( + LorexHCF.getInstance().getPlayTimeManager().getTotalPlayTime(target.getUniqueId()), true, true) + + ChatColor.GRAY + "."); + return true; + } + + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 1 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/PotsCommand.java b/src/me/bruce/factions/commands/PotsCommand.java new file mode 100644 index 0000000..4250fde --- /dev/null +++ b/src/me/bruce/factions/commands/PotsCommand.java @@ -0,0 +1,136 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.economy.EconomyManager; + +public class PotsCommand implements CommandExecutor, Listener { + + private final LorexHCF plugin; + + public PotsCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + Inventory pots = Bukkit.getServer().createInventory(null, 9 * 3, + ChatColor.RED + ChatColor.BOLD.toString() + "Pots gui"); + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + + ItemStack health = new ItemStack(Material.POTION, 1, (short) 16421); + ItemMeta hmeta = health.getItemMeta(); + hmeta.setDisplayName(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Health Potion"); + lore.add(ChatColor.RED + "press to buy for 500"); + hmeta.setLore(lore); + health.setItemMeta(hmeta); + + ItemStack slow = new ItemStack(Material.POTION, 1, (short) 16458); + ItemMeta smeta = health.getItemMeta(); + smeta.setDisplayName(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Slowness Potion"); + lore1.add(ChatColor.RED + "press to buy for 1000"); + smeta.setLore(lore1); + slow.setItemMeta(smeta); + + ItemStack invis = new ItemStack(Material.POTION, 1, (short) 8270); + ItemMeta imeta = invis.getItemMeta(); + imeta.setDisplayName(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Invisibility Potion"); + lore2.add(ChatColor.RED + "press to buy for 1000"); + smeta.setLore(lore2); + invis.setItemMeta(imeta); + + pots.setItem(13, health); + pots.setItem(10, slow); + pots.setItem(16, invis); + p.openInventory(pots); + return false; + } + + @EventHandler + public void InvenClick(InventoryClickEvent event) { + Player p = (Player) event.getWhoClicked(); + Inventory open = event.getInventory(); + ItemStack item = event.getCurrentItem(); + + if (open == null) { + return; + } + if (open.getName().equals(ChatColor.RED + ChatColor.BOLD.toString() + "Pots gui")) { + event.setCancelled(true); + if (item.equals(null) && !item.hasItemMeta()) { + Bukkit.getConsoleSender().sendMessage(""); + return; + } + + int senderBalance = p != null ? plugin.getEconomyManager().getBalance(p.getUniqueId()) : 1024; + + if (senderBalance < 99 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Health Potion")) { + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You Do not Have " + EconomyManager.ECONOMY_SYMBOL + "100 in you're bank."); + + } else if (senderBalance > 498 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Health Potion")) { + ItemStack health = new ItemStack(Material.POTION, 1, (short) 16421); + final UUID uuid = p.getUniqueId(); + plugin.getEconomyManager().subtractBalance(uuid, 500); + + p.getInventory().addItem(health); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "You Have Bought the Health potion for " + EconomyManager.ECONOMY_SYMBOL + "500"); + p.closeInventory(); + } + if (senderBalance < 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Slowness Potion")) { + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You Do not Have " + EconomyManager.ECONOMY_SYMBOL + "1000 in you're bank."); + + } else if (senderBalance > 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Slowness Potion")) { + ItemStack slow = new ItemStack(Material.POTION, 1, (short) 16458); + final UUID uuid = p.getUniqueId(); + plugin.getEconomyManager().subtractBalance(uuid, 1000); + + p.getInventory().addItem(slow); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "You Have Bought the Slowness potion for " + EconomyManager.ECONOMY_SYMBOL + "1000"); + p.closeInventory(); + } + if (senderBalance < 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Invisibility Potion")) { + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You Do not Have " + EconomyManager.ECONOMY_SYMBOL + "1000 in you're bank."); + + } else if (senderBalance > 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Invisibility Potion")) { + ItemStack invis = new ItemStack(Material.POTION, 1, (short) 8270); + final UUID uuid = p.getUniqueId(); + plugin.getEconomyManager().subtractBalance(uuid, 1000); + + p.getInventory().addItem(invis); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "You Have Bought the Invisibility potion for " + EconomyManager.ECONOMY_SYMBOL + "1000"); + p.closeInventory(); + } + } + } +} diff --git a/src/me/bruce/factions/commands/Pro.java b/src/me/bruce/factions/commands/Pro.java new file mode 100644 index 0000000..8e3dc91 --- /dev/null +++ b/src/me/bruce/factions/commands/Pro.java @@ -0,0 +1,66 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class Pro implements CommandExecutor { + + private final LorexHCF plugin; + + public Pro(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lPro Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} + + + diff --git a/src/me/bruce/factions/commands/PvPCommand.java b/src/me/bruce/factions/commands/PvPCommand.java new file mode 100644 index 0000000..0f0c681 --- /dev/null +++ b/src/me/bruce/factions/commands/PvPCommand.java @@ -0,0 +1,98 @@ +package me.bruce.factions.commands; + + +import com.google.common.collect.ImmutableList; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.DurationFormatter; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.timer.type.InvincibilityTimer; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to manage the {@link InvincibilityTimer} of {@link Player}s. + */ +public class PvPCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public PvPCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + InvincibilityTimer pvpTimer = plugin.getTimerManager().getInvincibilityTimer(); + + if (args.length < 1) { + printUsage(sender, label, pvpTimer); + return true; + } + + if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("off")) { + if (pvpTimer.getRemaining(player) <= 0L) { + sender.sendMessage(ChatColor.RED + "Your " + pvpTimer.getDisplayName() + ChatColor.RED + " is currently not active."); + return true; + } + + sender.sendMessage(ChatColor.RED + "Your " + pvpTimer.getDisplayName() + ChatColor.RED + " timer is now off."); + pvpTimer.clearCooldown(player); + return true; + } + + if (args[0].equalsIgnoreCase("remaining") || args[0].equalsIgnoreCase("time") || args[0].equalsIgnoreCase("left") || args[0].equalsIgnoreCase("check")) { + long remaining = pvpTimer.getRemaining(player); + if (remaining <= 0L) { + sender.sendMessage(ChatColor.RED + "Your " + pvpTimer.getDisplayName() + ChatColor.RED + " timer is currently not active."); + return true; + } + + sender.sendMessage(ChatColor.YELLOW + "Your " + pvpTimer.getDisplayName() + ChatColor.YELLOW + " timer is active for another " + ChatColor.BOLD + + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.YELLOW + (pvpTimer.isPaused(player) ? " and is currently paused" : "") + '.'); + + return true; + } + + printUsage(sender, label, pvpTimer); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 1 ? BukkitUtils.getCompletions(args, COMPLETIONS) : Collections.emptyList(); + } + + private static final ImmutableList COMPLETIONS = ImmutableList.of("enable", "time"); + + /** + * Prints the usage of this command to a sender. + * + * @param sender + * the sender to print for + * @param label + * the label used for command + */ + private void printUsage(CommandSender sender, String label, InvincibilityTimer pvpTimer) { + sender.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.STRIKETHROUGH + "-*-----------------------------------------*-"); + sender.sendMessage(ChatColor.GOLD.toString() + ChatColor.BOLD + "PVP Help" + ChatColor.GRAY + " (Page 1 of 1)"); + sender.sendMessage(ChatColor.YELLOW + "/" + label + " enable" + ChatColor.GRAY + " §7" + ChatColor.WHITE +"Removes your PVP Timer"); + sender.sendMessage(ChatColor.YELLOW + "/" + label + " time"+ ChatColor.GRAY + "§7 " + ChatColor.WHITE + "Check remaining PVP Timer"); + sender.sendMessage(ChatColor.YELLOW + "/lives " + ChatColor.GRAY + " §7" + ChatColor.WHITE + "Displays help for player lives."); + sender.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.STRIKETHROUGH + "-*-----------------------------------------*-"); + } +} diff --git a/src/me/bruce/factions/commands/RefundCommand.java b/src/me/bruce/factions/commands/RefundCommand.java new file mode 100644 index 0000000..a5f5e3c --- /dev/null +++ b/src/me/bruce/factions/commands/RefundCommand.java @@ -0,0 +1,92 @@ +package me.bruce.factions.commands; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import me.bruce.factions.LorexHCF; +import net.md_5.bungee.api.ChatColor; + +public class RefundCommand implements CommandExecutor, Listener { + private LorexHCF mainPlugin; + private Map rollbackInv; + + public Map getRollbackInv() { + return this.rollbackInv; + } + + public RefundCommand(final LorexHCF mainPlugin) { + this.mainPlugin = mainPlugin; + this.mainPlugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.mainPlugin); + this.rollbackInv = new HashMap(); + } + + public boolean onCommand(final CommandSender s, final Command c, final String alias, final String[] args) { + if (!s.hasPermission("core.refund")) { + s.sendMessage(ChatColor.RED + "You do not have permission."); + return true; + } + if (args.length != 1) { + s.sendMessage(ChatColor.RED + "Correct Usage: /" + c.getName() + " "); + return true; + } + final Player p = this.mainPlugin.getServer().getPlayer(args[0]); + if (p == null) { + s.sendMessage(ChatColor.RED + "Player is not online."); + return true; + } + if (!this.rollbackInv.containsKey(p.getUniqueId())) { + s.sendMessage(ChatColor.RED + p.getName() + " does not have a stored record of his/her inventory."); + } + else { + s.sendMessage(ChatColor.GREEN + p.getName() + "'s inventory has been restored."); + p.sendMessage(ChatColor.GREEN + "Your inventory was restored by " + s.getName() + "."); + final InventorySet invSet = this.rollbackInv.get(p.getUniqueId()); + p.getInventory().setContents(invSet.getInv()); + p.getInventory().setArmorContents(invSet.getArmor()); + } + return true; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDeath(final PlayerDeathEvent e) { + final UUID entityUUID = e.getEntity().getUniqueId(); + this.rollbackInv.put(entityUUID, new InventorySet(e.getEntity())); + } + + public class InventorySet + { + private Player p; + private ItemStack[] inv; + private ItemStack[] armor; + + public Player getP() { + return this.p; + } + + public ItemStack[] getInv() { + return this.inv; + } + + public ItemStack[] getArmor() { + return this.armor; + } + + public InventorySet(final Player p) { + this.p = p; + this.inv = p.getInventory().getContents(); + this.armor = p.getInventory().getArmorContents(); + } + } + } diff --git a/src/me/bruce/factions/commands/RegenCommand.java b/src/me/bruce/factions/commands/RegenCommand.java new file mode 100644 index 0000000..1bad313 --- /dev/null +++ b/src/me/bruce/factions/commands/RegenCommand.java @@ -0,0 +1,83 @@ +package me.bruce.factions.commands; + + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.struct.RegenStatus; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.ymls.SettingsYML; +import net.minecraft.util.org.apache.commons.lang3.time.DurationFormatUtils; + +import java.util.Collections; +import java.util.List; + +public class RegenCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public RegenCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); + if (playerFaction == null) { + sender.sendMessage(ChatColor.RED + "You are not in a faction."); + return true; + } + + RegenStatus regenStatus = playerFaction.getRegenStatus(); + switch (regenStatus) { + case FULL: + sender.sendMessage(ChatColor.RED + "Your faction currently has full DTR."); + return true; + case PAUSED: + sender.sendMessage(ChatColor.RED + "Your faction is currently on DTR freeze for another " + ChatColor.WHITE + + DurationFormatUtils.formatDurationWords(playerFaction.getRemainingRegenerationTime(), true, true) + + ChatColor.RED + '.'); + + return true; + case REGENERATING: + sender.sendMessage( + ChatColor.YELLOW + "Your faction currently has " + ChatColor.YELLOW + regenStatus.getSymbol() + ' ' + + playerFaction.getDeathsUntilRaidable() + ChatColor.YELLOW + + " DTR and is regenerating at a rate of " + ChatColor.GOLD + + SettingsYML.DTR_INCREMENT_BETWEEN_UPDATES + ChatColor.YELLOW + " every " + ChatColor.GOLD + + SettingsYML.DTR_WORDS_BETWEEN_UPDATES + ChatColor.YELLOW + + ". Your ETA for maximum DTR is " + ChatColor.RED + DurationFormatUtils + .formatDurationWords(getRemainingRegenMillis(playerFaction), true, true) + + ChatColor.YELLOW + '.'); + + return true; + } + + sender.sendMessage( + ChatColor.RED + "Unrecognised regeneration status, please inform an Developer or an System Admin."); + return true; + } + + public long getRemainingRegenMillis(PlayerFaction faction) { + long millisPassedSinceLastUpdate = System.currentTimeMillis() - faction.getLastDtrUpdateTimestamp(); + double dtrRequired = faction.getMaximumDeathsUntilRaidable() - faction.getDeathsUntilRaidable(); + return (long) ((SettingsYML.DTR_MILLIS_BETWEEN_UPDATES / SettingsYML.DTR_INCREMENT_BETWEEN_UPDATES) + * dtrRequired) - millisPassedSinceLastUpdate; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/RenameCommand.java b/src/me/bruce/factions/commands/RenameCommand.java new file mode 100644 index 0000000..66dcdb7 --- /dev/null +++ b/src/me/bruce/factions/commands/RenameCommand.java @@ -0,0 +1,58 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; + +public class RenameCommand implements CommandExecutor { + + private LorexHCF plugin; + + public RenameCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + public String getUsage(String label) { + return String.valueOf('/') + label + ' ' + ""; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if (args.length < 1) { + p.sendMessage(ChatColor.RED + "Usage: " + this.getUsage(label)); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&7If you want to use any color make sure you do & and then the color code.")); + } else { + ItemStack hand = p.getItemInHand(); + if (hand.getType() != Material.AIR) { + String name = ""; + for (int i = 0; i != args.length; i++) + name += args[i] + " "; + + ItemMeta meta = hand.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&r" + name)); + hand.setItemMeta(meta); + + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have successfully renamed your &c" + + hand.getType().name().toLowerCase() + " &7to &r" + name)); + } else { + p.sendMessage(ChatColor.RED + "You cannot rename Air!"); + + } + } + return true; + } + +} diff --git a/src/me/bruce/factions/commands/ReviveCommand.java b/src/me/bruce/factions/commands/ReviveCommand.java new file mode 100644 index 0000000..83d09d6 --- /dev/null +++ b/src/me/bruce/factions/commands/ReviveCommand.java @@ -0,0 +1,73 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import LorexMC.us.utils.BukkitUtils; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; + +public class ReviveCommand implements CommandExecutor, TabCompleter { + private final LorexHCF plugin; + + public ReviveCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(ChatColor.RED + "Player '" + ChatColor.WHITE + args[0] + ChatColor.RED + "' not found."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = LorexHCF.getInstance().getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + Command.broadcastCommandMessage(sender, + ChatColor.GREEN + "A staff member has successfully revived " + target.getName() + "."); + return false; + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length != 1) { + return Collections.emptyList(); + } + final List results = new ArrayList(); + for (final FactionUser factionUser : this.plugin.getUserManager().getUsers().values()) { + final Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + final String name = offlinePlayer.getName(); + if (name == null) { + continue; + } + results.add(name); + } + } + return BukkitUtils.getCompletions(args, results); + } +} diff --git a/src/me/bruce/factions/commands/RulesCommand.java b/src/me/bruce/factions/commands/RulesCommand.java new file mode 100644 index 0000000..d690052 --- /dev/null +++ b/src/me/bruce/factions/commands/RulesCommand.java @@ -0,0 +1,26 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class RulesCommand implements CommandExecutor{ + + public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&C&LSERVER RULES ")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cNo racism / excessive insults")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CSpamming is a kickable offense")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cAll server members, are treated the same (Staff, Donators, Players)")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CStaff cannot punish higher staff members [Only applied in game]")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CDDoSing / Doxing Threats, are a bannable offense on both the Discord and the Server.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cGeneral threats are a bannable offense on both the Discord and the Server.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cSuicidal jokes are a kickable offense on the Discord Server.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CNo screamers or IP loggers allowed. (Will result in a blacklist ingame & discord)")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cNo advertising other servers.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &c No voice changers / trolling staff.")); + return true; + } + +} diff --git a/src/me/bruce/factions/commands/SPCOMMAND.java b/src/me/bruce/factions/commands/SPCOMMAND.java new file mode 100644 index 0000000..0b597b7 --- /dev/null +++ b/src/me/bruce/factions/commands/SPCOMMAND.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class SPCOMMAND implements CommandExecutor{ + + public static ArrayList sp = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!sp.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7speed.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + sp.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisabled &7speed.")); + p.removePotionEffect(PotionEffectType.SPEED); + sp.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/SetPrefixCommand.java b/src/me/bruce/factions/commands/SetPrefixCommand.java new file mode 100644 index 0000000..be7b2d7 --- /dev/null +++ b/src/me/bruce/factions/commands/SetPrefixCommand.java @@ -0,0 +1,43 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import ru.tehkode.permissions.bukkit.PermissionsEx; + +public class SetPrefixCommand implements CommandExecutor +{ + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (!sender.hasPermission("zentrix.admin")) { + sender.sendMessage("§cNo permission."); + return true; + } + if (args.length == 0) { + sender.sendMessage("§cUsage: /setprefix "); + return true; + } + final Player pl = Bukkit.getPlayer(args[0]); + if (pl == null) { + sender.sendMessage("§cPlayer not found!"); + return true; + } + if (args.length < 2) { + sender.sendMessage("§cUsage: /setprefix "); + return true; + } + if (args[1].equals("remove")) { + + pl.sendMessage(LorexHCF.PREFIX + "Your prefix has been removed by: " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(sender.getName()).getPrefix() + sender.getName())); + sender.sendMessage(LorexHCF.PREFIX + "You have removed " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(pl.getName()).getPrefix() + pl.getName()) + "'s prefix!"); + return true; + } + pl.sendMessage(LorexHCF.PREFIX + "Your prefix has been set to: " + ChatColor.translateAlternateColorCodes('&', args[1]) + " by " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(sender.getName()).getPrefix() + sender.getName())); + sender.sendMessage(LorexHCF.PREFIX + "You have set " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(pl.getName()).getSuffix() + pl.getName()) + "'s prefix to: " + ChatColor.translateAlternateColorCodes('&', args[1])); + return true; + } +} diff --git a/src/me/bruce/factions/commands/SettingsCommand.java b/src/me/bruce/factions/commands/SettingsCommand.java new file mode 100644 index 0000000..980a725 --- /dev/null +++ b/src/me/bruce/factions/commands/SettingsCommand.java @@ -0,0 +1,264 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; + +public class SettingsCommand implements CommandExecutor, Listener { + + + public static ArrayList lines = new ArrayList(); + public static ArrayList scoreboard = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + Inventory pots = Bukkit.getServer().createInventory(null, 9 * 3, + ChatColor.BLUE + ChatColor.BOLD.toString() + "Settings GUI"); + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + + ItemStack health = new ItemStack(Material.BAKED_POTATO); + ItemMeta hmeta = health.getItemMeta(); + hmeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "ClearChat"); + lore.add(ChatColor.YELLOW + "This will only clear you're chat"); + hmeta.setLore(lore); + health.setItemMeta(hmeta); + + ItemStack slow = new ItemStack(Material.BLAZE_ROD); + ItemMeta smeta = health.getItemMeta(); + smeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Scoreboard"); + if(scoreboard.contains(p.getUniqueId())) { + lore1.add(ChatColor.YELLOW + "Balance on scoreboard §aEnabled§7!"); + smeta.setLore(lore1); + } + else { + lore1.add(ChatColor.YELLOW + "Balance on scoreboard §cDisabled§7!"); + smeta.setLore(lore1); + } + slow.setItemMeta(smeta); + + ItemStack invis = new ItemStack(Material.DIAMOND_BLOCK); + ItemMeta imeta = invis.getItemMeta(); + imeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Lines on scoreboard"); + if(lines.contains(p.getUniqueId())) { + lore2.add(ChatColor.YELLOW + "Lines on scoreboard §cDisabled§7!"); + imeta.setLore(lore2); + } + else { + lore2.add(ChatColor.YELLOW + "Lines on scoreboard §aEnabled§7!"); + imeta.setLore(lore2); + } + invis.setItemMeta(imeta); + + pots.setItem(13, health); + pots.setItem(10, slow); + pots.setItem(16, invis); + p.openInventory(pots); + return false; + } + + @EventHandler + public void InvenClick(InventoryClickEvent event) { + Player p = (Player) event.getWhoClicked(); + Inventory open = event.getInventory(); + ItemStack item = event.getCurrentItem(); + + if (open == null) { + return; + } + if (open.getName().equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Settings GUI")) { + + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "ClearChat")) { + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You're Chat Has Been Cleared."); + p.closeInventory(); + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Scoreboard")) { + if(scoreboard.contains(p.getUniqueId())) { + scoreboard.remove(p.getUniqueId()); + p.closeInventory(); + } + else { + scoreboard.add(p.getUniqueId()); + p.closeInventory(); + } + + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Lines on scoreboard")) { + if(lines.contains(p.getUniqueId())) { + lines.remove(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "No lines has been §cDisabled§7." ); + p.closeInventory(); + + } + else if(!lines.contains(p.getUniqueId())) { + lines.add(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "No lines has been §aEnabled§7." ); + p.closeInventory(); + + } + + } + } + } +} diff --git a/src/me/bruce/factions/commands/SpawnCommand.java b/src/me/bruce/factions/commands/SpawnCommand.java new file mode 100644 index 0000000..e515df6 --- /dev/null +++ b/src/me/bruce/factions/commands/SpawnCommand.java @@ -0,0 +1,42 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.ymls.SettingsYML; +import net.md_5.bungee.api.ChatColor; + +public class SpawnCommand implements CommandExecutor, Listener { + + + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + if(!(sender instanceof Player)) { + sender.sendMessage("Cannot use this command in console."); + return true; + } + Player p = (Player) sender; + if(!p.hasPermission("staff.spawn")) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» §cTravel to 0.0")); + return true; + } + else { + if(SettingsYML.KIT_MAP == true) { + p.teleport(new Location(Bukkit.getWorld("World"), 0,80,-1)); + } + } + if(SettingsYML.KIT_MAP == false) { + p.teleport(new Location(Bukkit.getWorld("World"), 0,73,-1)); + } + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &eYou Have teleported to spawn.")); + return true; + } + } + diff --git a/src/me/bruce/factions/commands/StaffInformation.java b/src/me/bruce/factions/commands/StaffInformation.java new file mode 100644 index 0000000..924419c --- /dev/null +++ b/src/me/bruce/factions/commands/StaffInformation.java @@ -0,0 +1,30 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class StaffInformation implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + + if (cmd.getName().equalsIgnoreCase("staffguide")) { + if (p.hasPermission("zorex.staffguide")) { + if (args.length == 0) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&8&m------------------------------------------- ")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» Staff Guide")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&8&m------------------------------------------- ")); + } else { + p.sendMessage(ChatColor.RED + "You Do Not Have Permission To Use this command"); + } + } + } + return false; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/StaffSettings.java b/src/me/bruce/factions/commands/StaffSettings.java new file mode 100644 index 0000000..f71ce62 --- /dev/null +++ b/src/me/bruce/factions/commands/StaffSettings.java @@ -0,0 +1,113 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; + +public class StaffSettings implements CommandExecutor, Listener { + + + public static ArrayList faithful = new ArrayList(); + public static ArrayList zorex = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + Inventory pots1 = Bukkit.getServer().createInventory(null, 9, + ChatColor.BLUE + ChatColor.BOLD.toString() + "Staff GUI"); + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + + ItemStack health = new ItemStack(Material.BAKED_POTATO); + ItemMeta hmeta = health.getItemMeta(); + hmeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Faithful Remake"); + lore.add(ChatColor.BLUE + ""); + hmeta.setLore(lore); + health.setItemMeta(hmeta); + + + + + ItemStack invis = new ItemStack(Material.DIAMOND_BLOCK); + ItemMeta imeta = invis.getItemMeta(); + imeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Zorex"); + invis.setItemMeta(imeta); + + pots1.setItem(0, health); + pots1.setItem(1, invis); + p.openInventory(pots1); + return true; + } + + @EventHandler + public void InvenClick(InventoryClickEvent event) { + Player p = (Player) event.getWhoClicked(); + Inventory open = event.getInventory(); + ItemStack item = event.getCurrentItem(); + + if (open == null) { + return; + } + if (open.getName().equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Staff GUI")) { + + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Faithful Remake")) { + if(faithful.contains(p.getUniqueId())) { + faithful.remove(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "You have §4Disabled §7Faithful."); + } + if(!faithful.contains(p.getUniqueId())) { + faithful.add(p.getUniqueId()); + p.closeInventory(); + p.sendMessage(LorexHCF.PREFIX + "You have §aEnabled §7Faithful."); + } + if(zorex.contains(p.getUniqueId())) { + zorex.remove(p.getUniqueId()); + p.closeInventory(); + p.sendMessage(LorexHCF.PREFIX + "Zorex was still on so we disabled it."); + } + p.closeInventory(); + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "NONE")) { + p.closeInventory(); + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Zorex")) { + if(zorex.contains(p.getUniqueId())) { + zorex.remove(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "You have §4Disabled §7Zorex."); + p.closeInventory(); + } + if(!zorex.contains(p.getUniqueId())) { + zorex.add(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "You have §aEnabled §7Zorex."); + p.closeInventory(); + } + if(faithful.contains(p.getUniqueId())) { + faithful.remove(p.getUniqueId()); + } + } + + } + + } + } + + diff --git a/src/me/bruce/factions/commands/StatsCommand.java b/src/me/bruce/factions/commands/StatsCommand.java new file mode 100644 index 0000000..4ed6de1 --- /dev/null +++ b/src/me/bruce/factions/commands/StatsCommand.java @@ -0,0 +1,31 @@ +package me.bruce.factions.commands; + +import org.bukkit.Statistic; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.md_5.bungee.api.ChatColor; + +public class StatsCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[] arg3) { + if(!(arg0 instanceof Player)) { + return true; + } + Player p = (Player) arg0; + arg0.sendMessage("§7§m----------------------------------------------"); + arg0.sendMessage(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Player Stats:"); + arg0.sendMessage(""); + arg0.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Kills§7:§f " + p.getStatistic(Statistic.PLAYER_KILLS)); + arg0.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Deaths§7:§f " + p.getStatistic(Statistic.DEATHS)); + arg0.sendMessage("§7§m----------------------------------------------"); + return true; + } +} + + + + diff --git a/src/me/bruce/factions/commands/Store.java b/src/me/bruce/factions/commands/Store.java new file mode 100644 index 0000000..f48e964 --- /dev/null +++ b/src/me/bruce/factions/commands/Store.java @@ -0,0 +1,5 @@ +package me.bruce.factions.commands; + +public class Store { + +} diff --git a/src/me/bruce/factions/commands/TLCommand.java b/src/me/bruce/factions/commands/TLCommand.java new file mode 100644 index 0000000..38df6c9 --- /dev/null +++ b/src/me/bruce/factions/commands/TLCommand.java @@ -0,0 +1,27 @@ +package me.bruce.factions.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TLCommand implements CommandExecutor { + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("No Console"); + return true; + } + final Player player = (Player)sender; + final int x = player.getLocation().getBlockX(); + final int y = player.getLocation().getBlockY(); + final int z = player.getLocation().getBlockZ(); + if (command.getName().equalsIgnoreCase("tl")) { + player.chat("/f c " + x + ", " + y + ", " + z); + return true; + } + return true; + } + } + + + diff --git a/src/me/bruce/factions/commands/Tablist.java b/src/me/bruce/factions/commands/Tablist.java new file mode 100644 index 0000000..3035903 --- /dev/null +++ b/src/me/bruce/factions/commands/Tablist.java @@ -0,0 +1,55 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class Tablist implements CommandExecutor, Listener { + + public static ArrayList oof = new ArrayList(); + public static ArrayList defaulty = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + if (args.length == 0) { + sender.sendMessage("Please say wich tablist you want"); + return true; + + } + if ((args.length == 1 && (args[0].equalsIgnoreCase("kitmap")))) { + sender.sendMessage( + ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7you have enabled Kitmap.")); + defaulty.remove(p); + oof.add(p); + return true; + } + if ((args.length == 1 && (args[0].equalsIgnoreCase("default")))) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7you have enabled default.")); + oof.remove(p); + defaulty.add(p); + return true; + } + else if(args.length == 1 ) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You Must choose either kitmap are default.")); + } + + return false; + } + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + oof.remove(p); + defaulty.add(p); + + } + +} diff --git a/src/me/bruce/factions/commands/TablistCommand.java b/src/me/bruce/factions/commands/TablistCommand.java new file mode 100644 index 0000000..84403ad --- /dev/null +++ b/src/me/bruce/factions/commands/TablistCommand.java @@ -0,0 +1,74 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; +import me.tablist.api.tablist.Xernos; +import me.tablist.api.tablist.adapter.TablistAdapter; +import net.md_5.bungee.api.ChatColor; + +public class TablistCommand implements CommandExecutor,Listener { + + public static ArrayList kits = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player p = (Player) sender; + Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GOLD + "Tablist Selector"); + ItemStack kits = new ItemStack(Material.DIAMOND_SWORD); + ItemMeta kmeta = kits.getItemMeta(); + kmeta.setDisplayName("§7Kitmap Tablist"); + kits.setItemMeta(kmeta); + + ItemStack normal = new ItemStack(Material.DIAMOND_SWORD); + ItemMeta nmeta = normal.getItemMeta(); + nmeta.setDisplayName("§7Default Tablist"); + normal.setItemMeta(nmeta); + + inv.setItem(0, kits); + inv.setItem(1, normal); + p.openInventory(inv); + return true; + } + + @EventHandler + public void onInventoryInteract(InventoryClickEvent e) { + Player p = (Player) e.getWhoClicked(); + if(e.getClickedInventory().getName().equalsIgnoreCase(ChatColor.GOLD + "Tablist Selector")) { + e.setCancelled(true); + if(e.getCurrentItem().getItemMeta() == null) { + return; + } + if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GRAY + "Kitmap Tablist")) { + p.sendMessage(LorexHCF.PREFIX + " You have selected the Kitmap tablist."); + TablistAdapter.tablist.add(p); + p.closeInventory(); + Xernos.getByPlayer(p).clearTab(); + + } + if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GRAY + "Default Tablist")) { + p.sendMessage(LorexHCF.PREFIX + " You have selected the Default tablist."); + p.closeInventory(); + TablistAdapter.tablist.remove(p); + Xernos.getByPlayer(p).clearTab(); + + + } + } + } + +} diff --git a/src/me/bruce/factions/commands/ToggleCapzoneEntryCommand.java b/src/me/bruce/factions/commands/ToggleCapzoneEntryCommand.java new file mode 100644 index 0000000..5236b93 --- /dev/null +++ b/src/me/bruce/factions/commands/ToggleCapzoneEntryCommand.java @@ -0,0 +1,49 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to toggle messages shown when entering or leaving + */ +public class ToggleCapzoneEntryCommand implements CommandExecutor, TabExecutor { + + private final LorexHCF plugin; + + public ToggleCapzoneEntryCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + FactionUser factionUser = plugin.getUserManager().getUser(((Player) sender).getUniqueId()); + boolean newStatus = !factionUser.isCapzoneEntryAlerts(); + factionUser.setCapzoneEntryAlerts(newStatus); + + sender.sendMessage( + ChatColor.YELLOW + "You will now " + (newStatus ? ChatColor.GREEN.toString() : ChatColor.RED + "un") + + "able" + ChatColor.YELLOW + " to see capture zone entry messages."); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/ToggleLightningCommand.java b/src/me/bruce/factions/commands/ToggleLightningCommand.java new file mode 100644 index 0000000..43c2343 --- /dev/null +++ b/src/me/bruce/factions/commands/ToggleLightningCommand.java @@ -0,0 +1,49 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to toggle the lightning strikes on death for a {@link Player}. + */ +public class ToggleLightningCommand implements CommandExecutor, TabExecutor { + + private final LorexHCF plugin; + + public ToggleLightningCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + FactionUser factionUser = plugin.getUserManager().getUser(((Player) sender).getUniqueId()); + boolean newShowLightning = !factionUser.isShowLightning(); + factionUser.setShowLightning(newShowLightning); + + sender.sendMessage(ChatColor.YELLOW + "You will now " + + (newShowLightning ? ChatColor.GREEN + "able" : ChatColor.RED + "unable") + ChatColor.YELLOW + + " to see lightning strikes on a players death."); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/Vip.java b/src/me/bruce/factions/commands/Vip.java new file mode 100644 index 0000000..cf139e1 --- /dev/null +++ b/src/me/bruce/factions/commands/Vip.java @@ -0,0 +1,65 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class Vip implements CommandExecutor{ + private final LorexHCF plugin; + + public Vip(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lVip Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} + + + diff --git a/src/me/bruce/factions/commands/WB.java b/src/me/bruce/factions/commands/WB.java new file mode 100644 index 0000000..1fbc412 --- /dev/null +++ b/src/me/bruce/factions/commands/WB.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class WB implements CommandExecutor{ + + ArrayList sp = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!sp.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7WATER BREATHING.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, Integer.MAX_VALUE, 1)); + sp.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisabled &7WATER BREATHING.")); + p.removePotionEffect(PotionEffectType.WATER_BREATHING); + sp.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/ZorexDeveloper.java b/src/me/bruce/factions/commands/ZorexDeveloper.java new file mode 100644 index 0000000..b405b50 --- /dev/null +++ b/src/me/bruce/factions/commands/ZorexDeveloper.java @@ -0,0 +1,17 @@ +package me.bruce.factions.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import me.bruce.factions.LorexHCF; + +public class ZorexDeveloper implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + sender.sendMessage(LorexHCF.PREFIX + "The developer of Zorex is Bruceboy!"); + return false; + } + +} diff --git a/src/me/bruce/factions/commands/ZorexRevive.java b/src/me/bruce/factions/commands/ZorexRevive.java new file mode 100644 index 0000000..d2c5339 --- /dev/null +++ b/src/me/bruce/factions/commands/ZorexRevive.java @@ -0,0 +1,63 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class ZorexRevive implements CommandExecutor{ + private final LorexHCF plugin; + + public ZorexRevive(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lZorex Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} + diff --git a/src/me/bruce/factions/commands/nv.java b/src/me/bruce/factions/commands/nv.java new file mode 100644 index 0000000..3e7cb2f --- /dev/null +++ b/src/me/bruce/factions/commands/nv.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class nv implements CommandExecutor{ + + ArrayList sp = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!sp.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7NIGHT VISION.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1)); + sp.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisabled &7NIGHT VISION.")); + p.removePotionEffect(PotionEffectType.NIGHT_VISION); + sp.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/randomtp.java b/src/me/bruce/factions/commands/randomtp.java new file mode 100644 index 0000000..bfd108b --- /dev/null +++ b/src/me/bruce/factions/commands/randomtp.java @@ -0,0 +1,40 @@ +package me.bruce.factions.commands; + + +import org.bukkit.command.*; +import org.bukkit.*; +import org.bukkit.entity.*; +import java.util.*; + +public class randomtp implements CommandExecutor{ + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + final Player player = (Player)sender; + final List players = new ArrayList(); + for (final Player players2 : Bukkit.getOnlinePlayers()) { + players.add(players2); + } + Collections.shuffle(players); + final Random random = new Random(); + final int randoms = random.nextInt(Bukkit.getOnlinePlayers().length); + final Player p = players.get(randoms); + if (player.canSee(p) && player.hasPermission("zorex.teleport")) { + player.teleport((Entity)p); + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY+ "You have teleported to " + p.getName()); + } + else if (player.canSee(p)) { + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + "You have found " + p.getName()); + } + else { + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + "Player could not be found."); + } + return true; +} +} + + + diff --git a/src/me/bruce/factions/conquest/ConquestExecutor.java b/src/me/bruce/factions/conquest/ConquestExecutor.java new file mode 100644 index 0000000..7574314 --- /dev/null +++ b/src/me/bruce/factions/conquest/ConquestExecutor.java @@ -0,0 +1,12 @@ +package me.bruce.factions.conquest; + +import LorexMC.us.utils.other.command.ArgumentExecutor; +import me.bruce.factions.LorexHCF; + +public class ConquestExecutor extends ArgumentExecutor { + + public ConquestExecutor(LorexHCF plugin) { + super("conquest"); + addArgument(new ConquestSetpointsArgument(plugin)); + } +} diff --git a/src/me/bruce/factions/conquest/ConquestSetpointsArgument.java b/src/me/bruce/factions/conquest/ConquestSetpointsArgument.java new file mode 100644 index 0000000..7c28a94 --- /dev/null +++ b/src/me/bruce/factions/conquest/ConquestSetpointsArgument.java @@ -0,0 +1,66 @@ +package me.bruce.factions.conquest; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.eventutils.EventType; +import me.bruce.factions.eventutils.tracker.ConquestTracker; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.ymls.SettingsYML; + +public class ConquestSetpointsArgument extends CommandArgument { + + private final LorexHCF plugin; + + public ConquestSetpointsArgument(LorexHCF plugin) { + super("setpoints", "Sets the points of a faction in the Conquest event", + "hcf.command.conquest.argument.setpoints"); + this.plugin = plugin; + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 3) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + Faction faction = plugin.getFactionManager().getFaction(args[1]); + + if (!(faction instanceof PlayerFaction)) { + sender.sendMessage( + ChatColor.RED + "FactionListener " + args[1] + " is either not found or is not a player faction."); + return true; + } + + Integer amount = JavaUtils.tryParseInt(args[2]); + + if (amount == null) { + sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number."); + return true; + } + + if (amount > SettingsYML.CONQUEST_REQUIRED_WIN_POINTS) { + sender.sendMessage( + ChatColor.RED + "Maximum points for Conquest is " + SettingsYML.CONQUEST_REQUIRED_WIN_POINTS + '.'); + return true; + } + + PlayerFaction playerFaction = (PlayerFaction) faction; + ((ConquestTracker) EventType.CONQUEST.getEventTracker()).setPoints(playerFaction, amount); + + Command.broadcastCommandMessage(sender, + ChatColor.YELLOW + "Set the points of faction " + playerFaction.getName() + " to " + amount + '.'); + return true; + } +} diff --git a/src/me/bruce/factions/deathban/Deathban.java b/src/me/bruce/factions/deathban/Deathban.java new file mode 100644 index 0000000..538b416 --- /dev/null +++ b/src/me/bruce/factions/deathban/Deathban.java @@ -0,0 +1,78 @@ +package me.bruce.factions.deathban; + +import org.bukkit.Location; +import org.bukkit.configuration.serialization.ConfigurationSerializable; + +import com.google.common.collect.Maps; + +import LorexMC.us.utils.PersistableLocation; + +import java.util.Map; + +public class Deathban implements ConfigurationSerializable { + private final String reason; + private final long creationMillis; + private final long expiryMillis; + private final PersistableLocation deathPoint; + + public Deathban(String reason, long duration, PersistableLocation deathPoint) { + this.reason = reason; + long millis = System.currentTimeMillis(); + this.creationMillis = millis; + this.expiryMillis = (millis + duration); + this.deathPoint = deathPoint; + } + + public Deathban(Map map) { + this.reason = ((String) map.get("reason")); + this.creationMillis = Long.parseLong((String) map.get("creationMillis")); + this.expiryMillis = Long.parseLong((String) map.get("expiryMillis")); + Object object = map.get("deathPoint"); + if (object != null) { + this.deathPoint = ((PersistableLocation) object); + } else { + this.deathPoint = null; + } + } + + @Override + public Map serialize() { + Map map = Maps.newLinkedHashMap(); + map.put("reason", this.reason); + map.put("creationMillis", Long.toString(this.creationMillis)); + map.put("expiryMillis", Long.toString(this.expiryMillis)); + if (this.deathPoint != null) { + map.put("deathPoint", this.deathPoint); + } + return map; + } + + public boolean isActive() { + return getRemaining() > 0L; + } + + public String getReason() { + return this.reason; + } + + public long getCreationMillis() { + return this.creationMillis; + } + + public long getExpiryMillis() { + return this.expiryMillis; + } + + public long getRemaining() { + return this.expiryMillis - System.currentTimeMillis(); + } + + public Location getDeathPoint() { + return this.deathPoint == null ? null : this.deathPoint.getLocation(); + } + + public long getInitialDuration() { + // TODO Auto-generated method stub + return 0; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/deathban/DeathbanListener.java b/src/me/bruce/factions/deathban/DeathbanListener.java new file mode 100644 index 0000000..412ed19 --- /dev/null +++ b/src/me/bruce/factions/deathban/DeathbanListener.java @@ -0,0 +1,182 @@ +/* */ package me.bruce.factions.deathban; + +/* */ +/* */ import java.util.UUID; +/* */ import java.util.concurrent.TimeUnit; + +/* */ import net.minecraft.util.gnu.trove.map.TObjectIntMap; +/* */ import net.minecraft.util.gnu.trove.map.TObjectLongMap; +/* */ import net.minecraft.util.gnu.trove.map.hash.TObjectLongHashMap; + +/* */ import org.bukkit.ChatColor; +/* */ import org.bukkit.entity.Player; +/* */ import org.bukkit.event.EventHandler; +/* */ import org.bukkit.event.EventPriority; +/* */ import org.bukkit.event.Listener; +/* */ import org.bukkit.event.entity.PlayerDeathEvent; +/* */ import org.bukkit.event.player.PlayerLoginEvent; +/* */ import org.bukkit.event.player.PlayerQuitEvent; +/* */ import org.bukkit.event.player.PlayerRespawnEvent; +/* */ import org.bukkit.scheduler.BukkitRunnable; +import LorexMC.us.utils.DurationFormatter; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.DelayedMessageRunnable; + +/* */ +/* */ public class DeathbanListener implements Listener +/* */ { + /* 29 */ private static final long RESPAWN_KICK_DELAY_MILLIS = TimeUnit.SECONDS.toMillis(10L); + /* 30 */ private static final long RESPAWN_KICK_DELAY_TICKS = RESPAWN_KICK_DELAY_MILLIS / 50L; + /* 31 */ private static final long LIFE_USE_DELAY_MILLIS = TimeUnit.SECONDS.toMillis(30L); + /* 32 */ private static final String LIFE_USE_DELAY_WORDS = org.apache.commons.lang3.time.DurationFormatUtils + .formatDurationWords(LIFE_USE_DELAY_MILLIS, true, true); + /* */ + /* */ private static final String DEATH_BAN_BYPASS_PERMISSION = "hcf.deathban.bypass"; + /* 35 */ private final TObjectIntMap respawnTickTasks = new net.minecraft.util.gnu.trove.map.hash.TObjectIntHashMap(); + /* 36 */ private final TObjectLongMap lastAttemptedJoinMap = new TObjectLongHashMap(); + /* */ private final LorexHCF plugin; + + /* */ + /* */ public DeathbanListener(LorexHCF plugin) { + /* 40 */ this.plugin = plugin; + /* */ } + + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) + /* */ public void onPlayerLogin(PlayerLoginEvent event) { + /* 45 */ Player player = event.getPlayer(); + /* 46 */ if (player.hasPermission("hcf.deathban.bypass")) { + /* 47 */ return; + /* */ } + /* */ + /* 50 */ FactionUser user = this.plugin.getUserManager().getUser(player.getUniqueId()); + /* 51 */ Deathban deathban = user.getDeathban(); + /* 52 */ if ((deathban == null) || (!deathban.isActive())) { + /* 53 */ return; + /* */ } + /* */ + /* 56 */ if (this.plugin.getEotwHandler().isEndOfTheWorld()) { + /* 57 */ event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.RED + + "Deathbanned for the entirety of the map due to EOTW.\nVisit www.zorex.us to view SOTW info."); + /* 58 */ return; + /* */ } + /* */ + /* 61 */ UUID uuid = player.getUniqueId(); + /* 62 */ int lives = this.plugin.getDeathbanManager().getLives(uuid); + /* */ + /* 64 */ String formattedRemaining = DurationFormatter.getRemaining(deathban.getRemaining(), true, false); + /* */ + /* 66 */ if (lives <= 0) { + /* 67 */ event.disallow(PlayerLoginEvent.Result.KICK_OTHER, + ChatColor.RED + "You are still Deathbanned \n Duration: " + ChatColor.WHITE + formattedRemaining); + /* */ + /* 70 */ return; + /* */ } + /* */ + /* 73 */ long millis = System.currentTimeMillis(); + /* 74 */ long lastAttemptedJoinMillis = this.lastAttemptedJoinMap.get(uuid); + /* */ + /* */ + /* 77 */ if ((lastAttemptedJoinMillis != this.lastAttemptedJoinMap.getNoEntryValue()) + && (lastAttemptedJoinMillis - millis < LIFE_USE_DELAY_MILLIS)) { + /* 78 */ this.lastAttemptedJoinMap.remove(uuid); + /* 79 */ user.removeDeathban(); + /* 80 */ lives = this.plugin.getDeathbanManager().takeLives(uuid, 1); + /* */ + /* 82 */ event.setResult(PlayerLoginEvent.Result.ALLOWED); + /* 83 */ new DelayedMessageRunnable(player, + ChatColor.YELLOW + "You have used a life for entry. You now have " + ChatColor.WHITE + lives + + ChatColor.YELLOW + " lives.").runTask(this.plugin); + /* */ + /* 85 */ return; + /* */ } + /* */ + /* */ + /* 89 */ String reason = deathban.getReason(); + /* 90 */ this.lastAttemptedJoinMap.put(uuid, millis + LIFE_USE_DELAY_MILLIS); + /* */ + /* 92 */ event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.RED + + "You are currently Deathbanned for Duration: " + ChatColor.WHITE + formattedRemaining + " \n" + + /* 93 */ ChatColor.RED + "You currently have " + ChatColor.WHITE + + (lives <= 0 ? "no" : Integer.valueOf(lives)) + " lives." + ChatColor.RED + + "You may use a life by reconnecting within " + ChatColor.WHITE + + /* 94 */ LIFE_USE_DELAY_WORDS + ChatColor.RED + "."); + /* */ } + + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) + /* */ public void onPlayerDeath(PlayerDeathEvent event) { + /* 99 */ final Player player = event.getEntity(); + /* 100 */ final Deathban deathban = this.plugin.getDeathbanManager().applyDeathBan(player, + event.getDeathMessage()); + /* 101 */ long remaining = deathban.getRemaining(); + /* 102 */ if ((remaining <= 0L) || (player.hasPermission("hcf.deathban.bypass"))) { + /* 103 */ return; + /* */ } + /* */ + /* 106 */ if ((RESPAWN_KICK_DELAY_MILLIS <= 0L) || (remaining < RESPAWN_KICK_DELAY_MILLIS)) { + /* 107 */ handleKick(player, deathban); + /* 108 */ return; + /* */ } + /* */ + /* */ + /* 112 */ this.respawnTickTasks.put(player.getUniqueId(), new BukkitRunnable() + /* */ { + /* */ @Override + public void run() { + /* 115 */ DeathbanListener.this.handleKick(player, deathban); + /* */ } + /* 117 */ }.runTaskLater(this.plugin, RESPAWN_KICK_DELAY_TICKS).getTaskId()); + /* */ } + + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + /* */ public void onPlayerRequestRespawn(PlayerRespawnEvent event) { + /* 122 */ Player player = event.getPlayer(); + /* 123 */ FactionUser user = this.plugin.getUserManager().getUser(player.getUniqueId()); + /* 124 */ Deathban deathban = user.getDeathban(); + /* 125 */ if ((deathban != null) && (deathban.getRemaining() > 0L)) { + /* 126 */ if (player.hasPermission("hcf.deathban.bypass")) { + /* 127 */ cancelRespawnKickTask(player); + /* 128 */ user.removeDeathban(); + /* 129 */ new DelayedMessageRunnable(player, ChatColor.RED + "Bypass access granted.") + .runTask(this.plugin); + /* */ + /* 131 */ return; + /* */ } + /* */ + /* */ + /* */ + /* 136 */ handleKick(player, deathban); + /* */ } + /* */ } + + /* */ + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + /* */ public void onPlayerQuit(PlayerQuitEvent event) + /* */ { + /* 144 */ cancelRespawnKickTask(event.getPlayer()); + /* */ } + + /* */ + /* */ private void cancelRespawnKickTask(Player player) { + /* 148 */ int taskId = this.respawnTickTasks.remove(player.getUniqueId()); + /* 149 */ if (taskId != this.respawnTickTasks.getNoEntryValue()) { + /* 150 */ org.bukkit.Bukkit.getScheduler().cancelTask(taskId); + /* */ } + /* */ } + + /* */ + /* */ private void handleKick(Player player, Deathban deathban) { + /* 155 */ if (this.plugin.getEotwHandler().isEndOfTheWorld()) { + /* 156 */ player.kickPlayer(ChatColor.RED + + "Deathbanned for the entirety of the map due to EOTW.\nVisit www.zorex.us for SOTW info!"); + /* */ } else { + /* 158 */ player.kickPlayer(ChatColor.RED + "You are now Deathbanned \n Duration: " + ChatColor.WHITE + + DurationFormatter.getRemaining(deathban.getRemaining(), true, false) + " " + ChatColor.WHITE + + deathban.getReason()); + /* */ } + /* */ } + /* */ } diff --git a/src/me/bruce/factions/deathban/DeathbanManager.java b/src/me/bruce/factions/deathban/DeathbanManager.java new file mode 100644 index 0000000..43ef5fc --- /dev/null +++ b/src/me/bruce/factions/deathban/DeathbanManager.java @@ -0,0 +1,102 @@ +package me.bruce.factions.deathban; + +import gnu.trove.map.TObjectIntMap; +import org.bukkit.entity.Player; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +public interface DeathbanManager { + + long MAX_DEATHBAN_TIME = TimeUnit.HOURS.toMillis(3); + + /** + * Gets the map storing the lives with the {@link UUID} string by the amount. + * + * @return the lives map + */ + TObjectIntMap getLivesMap(); + + /** + * Gets the lives of a player. + * + * @param uuid + * the uuid of player to get for + * @return the amount of owned lives + */ + int getLives(UUID uuid); + + /** + * Sets the amount of lives a player has. + * + * @param uuid + * the uuid of player to set for + * @param amount + * the amount to set at + * @return the new lives of the player + */ + int setLives(UUID uuid, int amount); + + /** + * Gives lives to a player. + * + * @param uuid + * the uuid of player to give to + * @param amount + * the amount to give + * @return the new lives of the player + */ + int addLives(UUID uuid, int amount); + + /** + * Takes lives away from a player. + * + * @param uuid + * the uuid of player to take for + * @param amount + * the amount to take + * @return the new lives of the player + */ + int takeLives(UUID uuid, int amount); + + /** + * Gets the deathban multiplier for a {@link Player}. + * + * @param player + * the {@link Player} to get for + * @return the deathban multiplier + */ + double getDeathBanMultiplier(Player player); + + /** + * Applies a {@link Deathban} to a {@link Player}. + * + * @param player + * the {@link Player} to apply to + * @param reason + * the reason for {@link Deathban} + * @return the {@link Deathban} that has been applied + */ + Deathban applyDeathBan(Player player, String reason); + + /** + * Applies a {@link Deathban} to a {@link Player}. + * + * @param uuid + * the uuid of player to apply to + * @param deathban + * the {@link Deathban} to be applied + * @return the {@link Deathban} that has been applied + */ + Deathban applyDeathBan(UUID uuid, Deathban deathban); + + /** + * Reloads deathban data from storage. + */ + void reloadDeathbanData(); + + /** + * Saves deathban data to storage. + */ + void saveDeathbanData(); +} diff --git a/src/me/bruce/factions/deathban/FlatFileDeathbanManager.java b/src/me/bruce/factions/deathban/FlatFileDeathbanManager.java new file mode 100644 index 0000000..61cb846 --- /dev/null +++ b/src/me/bruce/factions/deathban/FlatFileDeathbanManager.java @@ -0,0 +1,145 @@ +package me.bruce.factions.deathban; + +import gnu.trove.impl.Constants; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.procedure.TObjectIntProcedure; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.ymls.SettingsYML; + +import org.bukkit.Location; +import org.bukkit.configuration.MemorySection; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.Config; +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.PersistableLocation; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +public class FlatFileDeathbanManager implements DeathbanManager { + + private static final int MAX_DEATHBAN_MULTIPLIER = 300; + + private final LorexHCF plugin; + + private TObjectIntMap livesMap; + private Config livesConfig; + + public FlatFileDeathbanManager(LorexHCF plugin) { + this.plugin = plugin; + this.reloadDeathbanData(); + } + + @Override + public TObjectIntMap getLivesMap() { + return livesMap; + } + + @Override + public int getLives(UUID uuid) { + return livesMap.get(uuid); + } + + @Override + public int setLives(UUID uuid, int lives) { + livesMap.put(uuid, lives); + return lives; + } + + @Override + public int addLives(UUID uuid, int amount) { + return livesMap.adjustOrPutValue(uuid, amount, amount); + } + + @Override + public int takeLives(UUID uuid, int amount) { + return setLives(uuid, getLives(uuid) - amount); + } + + @Override + public double getDeathBanMultiplier(final Player player) { + for (int i = 5; i < 300; ++i) { + if (player.hasPermission("hcf.deathban.multiplier." + i)) { + return i / 100.0; + } + } + return 1.0; + } + + @Override + public Deathban applyDeathBan(Player player, String reason) { + Location location = player.getLocation(); + Faction factionAt = plugin.getFactionManager().getFactionAt(location); + + long duration = SettingsYML.DEFAULT_DEATHBAN_DURATION; + if (!factionAt.isDeathban()) { + duration /= 2; // non-deathban factions should be 50% qui + + } else if (player.hasPermission("hcf.deathban.rank.bronze")) { + duration = JavaUtils.parse("90m"); + } else if (player.hasPermission("hcf.deathban.rank.silver")) { + duration = JavaUtils.parse("75m"); + } else if (player.hasPermission("hcf.deathban.rank.cobalt")) { + duration = JavaUtils.parse("60m"); + } else if (player.hasPermission("hcf.deathban.rank.ruby")) { + duration = JavaUtils.parse("40m"); + } else if (player.hasPermission("hcf.deathban.rank.sapphire")) { + duration = JavaUtils.parse("30m"); + } else if (player.hasPermission("hcf.deathban.rank.titanium")) { + duration = JavaUtils.parse("20m"); + } else if (player.hasPermission("hcf.deathban.rank.amethyst")) { + duration = JavaUtils.parse("10m"); + } else if (player.hasPermission("hcf.deathban.rank.riots")) { + duration = JavaUtils.parse("5m"); + } else if (player.hasPermission("hcf.deathban.rank.default")) { + duration = JavaUtils.parse("120m"); + } + + duration *= getDeathBanMultiplier(player); + duration *= factionAt.getDeathbanMultiplier(); + return applyDeathBan(player.getUniqueId(), + new Deathban(reason, Math.min(MAX_DEATHBAN_TIME, duration), new PersistableLocation(location))); + } + + @Override + public Deathban applyDeathBan(UUID uuid, Deathban deathban) { + plugin.getUserManager().getUser(uuid).setDeathban(deathban); + return deathban; + } + + @Override + public void reloadDeathbanData() { + livesConfig = new Config(plugin, "lives"); + Object object = livesConfig.get("lives"); + if (object instanceof MemorySection) { + MemorySection section = (MemorySection) object; + Set keys = section.getKeys(false); + livesMap = new TObjectIntHashMap<>(keys.size(), Constants.DEFAULT_LOAD_FACTOR, 0); + for (String id : keys) { + livesMap.put(UUID.fromString(id), livesConfig.getInt(section.getCurrentPath() + "." + id)); + } + } else { + livesMap = new TObjectIntHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, 0); + } + } + + @Override + public void saveDeathbanData() { + Map saveMap = new LinkedHashMap<>(livesMap.size()); + livesMap.forEachEntry(new TObjectIntProcedure() { + @Override + public boolean execute(UUID uuid, int i) { + saveMap.put(uuid.toString(), i); + return true; + } + }); + + livesConfig.set("lives", saveMap); + livesConfig.save(); + } +} diff --git a/src/me/bruce/factions/deathban/StaffReviveCommand.java b/src/me/bruce/factions/deathban/StaffReviveCommand.java new file mode 100644 index 0000000..17ea4b7 --- /dev/null +++ b/src/me/bruce/factions/deathban/StaffReviveCommand.java @@ -0,0 +1,84 @@ +package me.bruce.factions.deathban; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import LorexMC.us.utils.BukkitUtils; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +public class StaffReviveCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public StaffReviveCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + + OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); // TODO: breaking + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[0] + ChatColor.GOLD + "' not found."); + return true; + } + + UUID targetUUID = target.getUniqueId(); + FactionUser factionTarget = LorexHCF.getInstance().getUserManager().getUser(targetUUID); + Deathban deathban = factionTarget.getDeathban(); + + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + + factionTarget.removeDeathban(); + Command.broadcastCommandMessage(sender, ChatColor.LIGHT_PURPLE + "Staff revived " + target.getName() + "."); + // sender.sendMessage(ChatColor.GREEN +"You have revived: " + target.getName() + + // ChatColor.GRAY + ChatColor.ITALIC + "(Click here to refund + // items)").setHoverText(ChatColor.GREEN + "Click here to refund items for: " + + // ChatColor.GRAY + + // target.getPlayer().getName().setClick(ClickAction.RUN_COMMAND, "/inv " + + // target.getPlayer().getName())); + return false; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 1) { + return Collections.emptyList(); + } + + List results = new ArrayList<>(); + for (FactionUser factionUser : plugin.getUserManager().getUsers().values()) { + Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + String name = offlinePlayer.getName(); + if (name != null) { + results.add(name); + } + } + } + + return BukkitUtils.getCompletions(args, results); + } + +} diff --git a/src/me/bruce/factions/deathban/lives/LivesExecutor.java b/src/me/bruce/factions/deathban/lives/LivesExecutor.java new file mode 100644 index 0000000..701a78a --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/LivesExecutor.java @@ -0,0 +1,23 @@ +package me.bruce.factions.deathban.lives; + +import LorexMC.us.utils.other.command.ArgumentExecutor; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.lives.args.*; + +/** + * Handles the execution and tab completion of the lives command. + */ +public class LivesExecutor extends ArgumentExecutor { + + public LivesExecutor(LorexHCF plugin) { + super("lives"); + + addArgument(new LivesCheckArgument(plugin)); + addArgument(new LivesCheckDeathbanArgument(plugin)); + addArgument(new LivesClearDeathbansArgument(plugin)); + addArgument(new LivesGiveArgument(plugin)); + addArgument(new LivesReviveArgument(plugin)); + addArgument(new LivesSetArgument(plugin)); + addArgument(new LivesSetDeathbanTimeArgument()); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/deathban/lives/args/LivesCheckArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesCheckArgument.java new file mode 100644 index 0000000..0dca97a --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesCheckArgument.java @@ -0,0 +1,63 @@ +package me.bruce.factions.deathban.lives.args; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; + +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to check how many lives a {@link Player} has. + */ +public class LivesCheckArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesCheckArgument(LorexHCF plugin) { + super("check", "Check how much lives a player has"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + OfflinePlayer target; + if (args.length > 1) { + target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking + } else if (sender instanceof Player) { + target = (Player) sender; + } else { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found."); + return true; + } + + int targetLives = plugin.getDeathbanManager().getLives(target.getUniqueId()); + + sender.sendMessage(target.getName() + ChatColor.YELLOW + " has " + ChatColor.LIGHT_PURPLE + targetLives + + ChatColor.YELLOW + ' ' + (targetLives == 1 ? "life" : "lives") + '.'); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 2 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesCheckDeathbanArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesCheckDeathbanArgument.java new file mode 100644 index 0000000..762d594 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesCheckDeathbanArgument.java @@ -0,0 +1,101 @@ +package me.bruce.factions.deathban.lives.args; + +import com.google.common.base.Strings; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.DateTimeFormats; + +import org.apache.commons.lang3.time.DurationFormatUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to check the {@link Deathban} of a + * {@link Player}. + */ +public class LivesCheckDeathbanArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesCheckDeathbanArgument(LorexHCF plugin) { + super("checkdeathban", "Check the deathban cause of player"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found."); + return true; + } + + Deathban deathban = plugin.getUserManager().getUser(target.getUniqueId()).getDeathban(); + + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + + sender.sendMessage(ChatColor.DARK_AQUA + "Deathban cause of " + target.getName() + '.'); + sender.sendMessage(ChatColor.GRAY + " Time: " + DateTimeFormats.HR_MIN.format(deathban.getCreationMillis())); + sender.sendMessage(ChatColor.GRAY + " Duration: " + + DurationFormatUtils.formatDurationWords(deathban.getInitialDuration(), true, true)); + + Location location = deathban.getDeathPoint(); + if (location != null) { + sender.sendMessage(ChatColor.GRAY + " Location: (" + location.getBlockX() + ", " + location.getBlockY() + + ", " + location.getBlockZ() + ") - " + location.getWorld().getName()); + } + + sender.sendMessage( + ChatColor.GRAY + " Reason: [" + Strings.nullToEmpty(deathban.getReason()) + ChatColor.GREEN + "]"); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 2) { + return Collections.emptyList(); + } + + List results = new ArrayList<>(); + for (FactionUser factionUser : plugin.getUserManager().getUsers().values()) { + Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + String name = offlinePlayer.getName(); + if (name != null) { + results.add(name); + } + } + } + + return results; + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesClearDeathbansArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesClearDeathbansArgument.java new file mode 100644 index 0000000..71b0010 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesClearDeathbansArgument.java @@ -0,0 +1,40 @@ +package me.bruce.factions.deathban.lives.args; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; + +/** + * An {@link CommandArgument} used to clear all {@link Deathban}s. + */ +public class LivesClearDeathbansArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesClearDeathbansArgument(LorexHCF plugin) { + super("cleardeathbans", "Clears the global deathbans"); + this.plugin = plugin; + this.aliases = new String[] { "resetdeathbans" }; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName(); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + for (FactionUser user : plugin.getUserManager().getUsers().values()) { + user.removeDeathban(); + } + + Command.broadcastCommandMessage(sender, ChatColor.YELLOW + "All death-bans have been cleared."); + return true; + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesGiveArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesGiveArgument.java new file mode 100644 index 0000000..f2e9d91 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesGiveArgument.java @@ -0,0 +1,82 @@ +package me.bruce.factions.deathban.lives.args; + +import me.bruce.factions.LorexHCF; +import com.google.common.primitives.Ints; + +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import LorexMC.us.utils.other.command.CommandArgument; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import java.util.Collections; +import java.util.List; + +public class LivesGiveArgument extends CommandArgument { + private final LorexHCF plugin; + private static final String PERMISSION = "hcf.command.lives.argument.give.bypass"; + + public LivesGiveArgument(LorexHCF plugin) { + super("give", "Help someone out by giving them live(s)"); + this.plugin = plugin; + this.aliases = new String[] { "transfer", "send", "pay", "add" }; + this.permission = "hcf.command.lives.argument." + this.getName(); + } + + @Override + public String getUsage(String label) { + return "" + '/' + label + ' ' + this.getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 3) { + sender.sendMessage(ChatColor.RED + "Usage: " + this.getUsage(label)); + return true; + } + Integer amount = Ints.tryParse(args[2]); + if (amount == null) { + sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number."); + return true; + } + if (amount <= 0) { + sender.sendMessage(ChatColor.RED + "The amount of lives must be positive."); + return true; + } + OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[1])); + return true; + } + Player onlineTarget = target.getPlayer(); + if (sender instanceof Player && !sender.hasPermission(PERMISSION)) { + Player player = (Player) sender; + int ownedLives = this.plugin.getDeathbanManager().getLives(player.getUniqueId()); + if (amount > ownedLives) { + sender.sendMessage(ChatColor.RED + "You tried to give " + target.getName() + ' ' + amount + + " lives, but you only have " + ownedLives + '.'); + return true; + } + this.plugin.getDeathbanManager().takeLives(player.getUniqueId(), amount); + } + final int targetLives = this.plugin.getDeathbanManager().getLives(target.getUniqueId()); + this.plugin.getDeathbanManager().addLives(target.getUniqueId(), amount); + sender.sendMessage(ChatColor.YELLOW + "You have sent " + ChatColor.GOLD + target.getName() + ChatColor.YELLOW + + ' ' + amount + ' ' + (amount > 1 ? "life" : "lives") + '.'); + sender.sendMessage(ChatColor.GREEN + "Remaining Lives: " + ChatColor.RED + targetLives + ChatColor.RED + ' ' + + ((targetLives == 1) ? "life" : "lives") + '.'); + if (onlineTarget != null) { + onlineTarget.sendMessage(ChatColor.GOLD + sender.getName() + ChatColor.YELLOW + " has sent you " + + ChatColor.GOLD + amount + ' ' + (amount > 1 ? "life" : "lives") + '.'); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 2 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesReviveArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesReviveArgument.java new file mode 100644 index 0000000..d966672 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesReviveArgument.java @@ -0,0 +1,140 @@ +package me.bruce.factions.deathban.lives.args; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.faction.struct.Relation; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.ymls.SettingsYML; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageRecipient; + +import java.util.*; + +/** + * An {@link CommandArgument} used to revive {@link Deathban}ned + * {@link Player}s. + */ +public class LivesReviveArgument extends CommandArgument { + + private static final String REVIVE_BYPASS_PERMISSION = "hcf.revive.bypass"; + private static final String PROXY_CHANNEL_NAME = "BungeeCord"; + + private final LorexHCF plugin; + + public LivesReviveArgument(LorexHCF plugin) { + super("revive", "Revive a death-banned player"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, PROXY_CHANNEL_NAME); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + ArrayList cooldown = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found."); + return true; + } + + UUID targetUUID = target.getUniqueId(); + FactionUser factionTarget = plugin.getUserManager().getUser(targetUUID); + Deathban deathban = factionTarget.getDeathban(); + + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + + Relation relation = Relation.ENEMY; + if (sender instanceof Player) { + if (!sender.hasPermission(REVIVE_BYPASS_PERMISSION)) { + if (plugin.getEotwHandler().isEndOfTheWorld()) { + sender.sendMessage(ChatColor.RED + "You cannot revive players during EOTW."); + return true; + } + } + + Player player = (Player) sender; + UUID playerUUID = player.getUniqueId(); + int selfLives = plugin.getDeathbanManager().getLives(playerUUID); + + if (selfLives <= 0) { + sender.sendMessage(ChatColor.RED + "You do not have any lives."); + return true; + } + + plugin.getDeathbanManager().setLives(playerUUID, selfLives - 1); + PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); + relation = playerFaction == null ? Relation.ENEMY + : playerFaction.getFactionRelation(plugin.getFactionManager().getPlayerFaction(targetUUID)); + sender.sendMessage(ChatColor.YELLOW + "You have used a life to revive " + relation.toChatColour() + + target.getName() + ChatColor.YELLOW + '.'); + } else { + sender.sendMessage(ChatColor.YELLOW + "You have revived " + SettingsYML.ENEMY_COLOUR + target.getName() + + ChatColor.YELLOW + '.'); + } + + if (sender instanceof PluginMessageRecipient) { + // NOTE: This server needs at least 1 player online. + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Message"); + out.writeUTF(args[1]); + + String serverDisplayName = ChatColor.GREEN + "LorexHCF"; // TODO: Non hard-coded server display name. + out.writeUTF(relation.toChatColour() + sender.getName() + ChatColor.GOLD + " has just revived you from " + + serverDisplayName + ChatColor.GOLD + '.'); + ((PluginMessageRecipient) sender).sendPluginMessage(plugin, PROXY_CHANNEL_NAME, out.toByteArray()); + } + + factionTarget.removeDeathban(); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 2) { + return Collections.emptyList(); + } + + List results = new ArrayList<>(); + Collection factionUsers = plugin.getUserManager().getUsers().values(); + for (FactionUser factionUser : factionUsers) { + Deathban deathban = factionUser.getDeathban(); + if (deathban == null || !deathban.isActive()) + continue; + + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + String offlineName = offlinePlayer.getName(); + if (offlineName != null) { + results.add(offlinePlayer.getName()); + } + } + + return results; + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesSetArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesSetArgument.java new file mode 100644 index 0000000..dc87da1 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesSetArgument.java @@ -0,0 +1,68 @@ +package me.bruce.factions.deathban.lives.args; + +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; + +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to set the lives of {@link Player}s. + */ +public class LivesSetArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesSetArgument(LorexHCF plugin) { + super("set", "Set how much lives a player has"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 3) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + Integer amount = JavaUtils.tryParseInt(args[2]); + + if (amount == null) { + sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number."); + return true; + } + + OfflinePlayer target = BukkitUtils.offlinePlayerWithNameOrUUID(args[1]); + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[1])); + return true; + } + + plugin.getDeathbanManager().setLives(target.getUniqueId(), amount); + + sender.sendMessage(ChatColor.YELLOW + target.getName() + " now has " + ChatColor.GOLD + amount + + ChatColor.YELLOW + " lives."); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 2 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesSetDeathbanTimeArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesSetDeathbanTimeArgument.java new file mode 100644 index 0000000..7a2c54e --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesSetDeathbanTimeArgument.java @@ -0,0 +1,57 @@ +package me.bruce.factions.deathban.lives.args; + +import org.apache.commons.lang3.time.DurationFormatUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.ymls.SettingsYML; + +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to set the base {@link Deathban} time, not + * including multipliers, etc. + */ +public class LivesSetDeathbanTimeArgument extends CommandArgument { + + public LivesSetDeathbanTimeArgument() { + super("setdeathbantime", "Sets the base deathban time"); + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + "